Class: Taskmeister::TaskList
- Inherits:
-
Object
- Object
- Taskmeister::TaskList
- Defined in:
- lib/taskmeister/task_list.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add(task) ⇒ Object
- #complete(short_id) ⇒ Object
- #details(short_id) ⇒ Object
-
#initialize(tasks) ⇒ TaskList
constructor
A new instance of TaskList.
- #replace(short_id, new_text) ⇒ Object
- #tasks ⇒ Object
- #to_short_list ⇒ Object
Constructor Details
#initialize(tasks) ⇒ TaskList
Returns a new instance of TaskList.
3 4 5 6 7 8 9 |
# File 'lib/taskmeister/task_list.rb', line 3 def initialize(tasks) @hash = {} tasks.each do |t| add(t) end end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 |
# File 'lib/taskmeister/task_list.rb', line 23 def [](key) @hash[key] end |
#add(task) ⇒ Object
27 28 29 30 |
# File 'lib/taskmeister/task_list.rb', line 27 def add(task) prefix = assign_short_code_to_task(task) @hash[prefix] = task end |
#complete(short_id) ⇒ Object
32 33 34 |
# File 'lib/taskmeister/task_list.rb', line 32 def complete(short_id) @hash.delete(short_id) end |
#details(short_id) ⇒ Object
43 44 45 46 47 |
# File 'lib/taskmeister/task_list.rb', line 43 def details(short_id) return [] unless @hash.has_key?(short_id) self[short_id].to_markdown end |
#replace(short_id, new_text) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/taskmeister/task_list.rb', line 36 def replace(short_id, new_text) task = self[short_id] return unless task @hash[short_id] = Task.new(new_text, task.id, task.notes) end |
#tasks ⇒ Object
19 20 21 |
# File 'lib/taskmeister/task_list.rb', line 19 def tasks @hash.values end |
#to_short_list ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/taskmeister/task_list.rb', line 11 def to_short_list longest_id = @hash.keys.max_by(&:length) @hash.map { |id, task| marker = task.notes? ? " »" : "" "%-#{longest_id.length}s - %s%s" % [id, task.text, marker] } end |