Created
April 17, 2012 06:05
-
-
Save lfborjas/2403819 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
class Date | |
def week_range | |
(self - self.wday .. self + (7 - self.wday) ) | |
end | |
end | |
class Planner | |
#constructor | |
def initialize | |
week = Date.today.week_range | |
#qué hará esta línea? | |
@dates = Hash[ week.map{|d| d.strftime("%A")}.zip(week.to_a) ] | |
@days = {} | |
end | |
def [](day) | |
@days[day.capitalize] | |
end | |
def []=(day, data) | |
day.capitalize! | |
unless @days[day] | |
@days[day] = [data] | |
else | |
@days[day] << data | |
end | |
end | |
def planned?(day) | |
@days.include? day.capitalize | |
end | |
def dump | |
File.open("#{Date.today.cweek}.agenda", 'w') do |f| | |
@dates.each do |day, date| | |
if planned?(day) | |
f << "#{date.to_s}: #{@days[day].join(",")}\n" | |
end | |
end | |
end | |
end | |
end | |
class REPL | |
#estos son métodos de clase | |
def self.start | |
#instanciación | |
week = Planner.new | |
loop do | |
print "agenda> " | |
day = gets.chomp | |
is_query = day.end_with?("?") | |
break if day.downcase.eql?("exit") | |
day.gsub!('?', '') | |
unless is_query | |
unless week.planned?(day) | |
print "what are you doing on #{day}?> " | |
else | |
print "what else are you doing on #{day}?> " | |
end | |
activity = gets.chomp | |
week[day] = activity | |
else | |
if week.planned?(day) | |
puts "On #{day} you have #{week[day].join(", ")}" | |
else | |
puts "You have nothing on #{day}" | |
end | |
end | |
end | |
week.dump | |
end | |
end | |
REPL.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment