Created
August 15, 2014 20:46
-
-
Save case-eee/4daaba6f3ec566823b2b to your computer and use it in GitHub Desktop.
todo-example (FYI this code won't actually run!)
This file contains 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
# What classes do you need? | |
# Remember, there are four high-level responsibilities, each of which have multiple sub-responsibilities: | |
require 'csv' | |
class Todo | |
end | |
class List | |
attr_reader :file, :tasks | |
attr_accessor :list | |
def initialize(file) | |
@file = file | |
@list = CSV.read(file) | |
@complete = false | |
@tasks = [] | |
end | |
def load_list | |
@list.each do |row| | |
@tasks << Task.new(row) | |
end | |
# return @list if @list.length == 0 | |
# @list.map! { |uncheck| ["[ ] " + uncheck[0]] } | |
end | |
# def to_s | |
# "#{@list}" | |
# end | |
def add(task) | |
@tasks << Task.new(task) | |
save(@tasks) | |
end | |
def remove(index) | |
x = @tasks.delete_at(index).join | |
"You have removed #{x}" | |
save(@tasks) | |
end | |
def save(task) | |
CSV.foreach #saving the new collection of tasks) | |
end | |
def complete(index) | |
@tasks[index+1].map! { |check| check.gsub(/\W\s\W/, '[X]') } | |
# if complete = | |
# "[x]" + | |
# else | |
# "[ ] #{}" | |
# end | |
end | |
def display_all | |
@tasks.each_with_index do |task, index| | |
"#{index + 1}" + task.display_tasks | |
end | |
# @list.join("\n") | |
end | |
end | |
class Task | |
attr_reader :task | |
def initialize(args) | |
@text = args['text'] | |
@complete = false | |
# @task = [] | |
# @task << task | |
end | |
def display_tasks | |
puts "#{text}" | |
end | |
end | |
class Interface | |
end | |
# list = List.new('todo_blank.csv') | |
list = List.new('todo.csv') | |
list.load_list | |
# p list.list | |
r = Task.new("walk the dog").task | |
list.add(r) | |
list.display_all | |
list.remove(13) | |
list.display_all | |
list | |
list.complete(0) | |
puts list.display_all | |
# p list.add() | |
# p tasks = list.display_all | |
if ARGV.any? | |
case ARGV[0] | |
when 'add' | |
list.add(ARGV[1]) | |
list.save | |
when 'delete' | |
list.delete(ARGV[1]) | |
list.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment