Skip to content

Instantly share code, notes, and snippets.

@muchness
Forked from dbc-challenges/todo.csv
Last active December 22, 2015 09:39
Show Gist options
  • Save muchness/3012db84a2c1e5655b68 to your computer and use it in GitHub Desktop.
Save muchness/3012db84a2c1e5655b68 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Move with Lil to the black mountain hills of Dakota
Lose Lil to Danny
Get hit in the eye by Danny
Walk into town seeking revenge
Book room at local saloon
Check into room and read Gideon's bible
Drink too much gin
Overhear Lil and Danny in neighboring room
Burst into neighboring room and declare a showdown
Get shot by Danny and collapse in corner
Visit doctor
Return to room and read Gideon's bible
Sing along! D'do d'do d'do do do d'do d'do d'do
# What classes do you need?
# Remember, there are four high-level responsibilities, each of which have multiple sub-responsibilities:
# 1. Gathering user input and taking the appropriate action (controller)
# 2. Displaying information to the user (view)
# 3. Reading and writing from the todo.txt file (model)
# 4. Manipulating the in-memory objects that model a real-life TODO list (domain-specific model)
# Note that (4) is where the essence of your application lives.
# Pretty much every application in the universe has some version of responsibilities (1), (2), and (3).
require 'CSV'
class List
attr_reader :list
def initialize
@list = []
end
def add_task(new_task)
@list << new_task
end
# def delete_task
# # delete by index
# end
end
class Task
attr_reader :text
def initialize(task_content)
@done = false
@text = task_content
end
def done
return "[X]" if @done
"[ ]"
end
def completed
end
end
class ListView
def initialize(task_list)
@list = task_list
end
def show_list
@list.list.each_with_index do |task, display_number|
puts "#{task.done} #{display_number + 1}. #{task.text}"
end
end
end
class Parser
def open_file(todos)
CSV.foreach('todo.csv') do |row|
todos.list << Task.new(row[0])
end
end
def mark_task_complete(task_number)
end
end
todos = List.new
parser = Parser.new
parser.open_file(todos)
list_view = ListView.new(todos)
task1 = Task.new("walk the dog")
task2 = Task.new("buy beer")
todos.add_task(task1)
todos.add_task(task2)
list_view.show_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment