Skip to content

Instantly share code, notes, and snippets.

@dladowitz
Created June 29, 2012 01:14
Show Gist options
  • Save dladowitz/3015071 to your computer and use it in GitHub Desktop.
Save dladowitz/3015071 to your computer and use it in GitHub Desktop.
ToDo app for Shereef's task_spec.rb
# Uses spec files from: https://github.com/devbootcamp/todo/tree/tests
class Task
def initialize(task_name, date_created = Time.now, date_completed = nil)
@task = task_name
@date_created = date_created
@date_completed = date_completed
end
def to_s
"#{@task} ; #{@date_created} ; #{@date_completed}"
end
def self.from_string(string)
split_string = string.split(" ; ")
@name = split_string[0]
@creation_time = split_string[1]
if split_string[2].empty? == true
@completed_time = nil
else
@completed_time = split_string[2].strip
end
self.new(@name, @creation_time, @completed_time)
end
def complete?
if !@date_completed.empty?
true
else
false
end
end
def incomplete?
if @date_completed.empty?
false
else
true
end
end
def complete!
@date_completed = Time.now
end
end
task1 = Task.from_string("eat food ; 2012-06-25 23:18:31 -0700 ; 2012-06-25 23:18:31 -0700")
puts task1.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment