Skip to content

Instantly share code, notes, and snippets.

@dladowitz
Created June 29, 2012 01:12
Show Gist options
  • Save dladowitz/3015067 to your computer and use it in GitHub Desktop.
Save dladowitz/3015067 to your computer and use it in GitHub Desktop.
Todo code for Shereef's list_spec.rb
# uses spec files from: https://github.com/devbootcamp/todo/tree/tests
require './task.rb'
class List
def initialize(file_name)
@list = IO.readlines(file_name)
# puts @list[0].class
# puts @list.length
# @list = [1,2,3]
end
def print_tasks(completed_status)
if completed_status == {}
# puts "In the first block"
@list
elsif completed_status[:status] == :complete
# puts "In in the second block"
@task_array = []
@list.each do |task|
# puts task.class
# puts Task.from_string(task).class
@task_array << Task.from_string(task)
end
# puts "This is the @task_array #{@task_array.inspect}"
@task_array.each do |task|
# puts task.inspect
# puts task.class
@completed = []
if task.complete? == true
@completed << task
end
end
p @completed
@completed
elsif completed_status[:status] == :incomplete
# puts "In in the third block"
@task_array = []
@list.each do |task|
@task_array << Task.from_string(task)
end
# puts "This is the @task_array #{@task_array[0].class}"
puts @task_array.inspect
@incomplete = []
@task_array.each do |task|
puts task.inspect
p task.to_s
p task.complete?
# puts task.class
if task.complete? == false
@incomplete << task
# puts "I am after the second << "
end
end
p @incomplete
@incomplete
else
puts "I didn't get caught"
end
end
def add_task(task_name)
@list << Task.new(task_name)
end
def delete_task(task_index)
@list.delete_at(task_index-1)
end
def complete_task(task_index)
# puts "This is the @list: #{@list.inspect}"
# puts "This is @list[0]: #{@list[0].inspect}"
@list[task_index-1].complete!
end
end
#
# @list = List.new("todo_5.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment