Class: Taskmeister::TaskList
- Inherits:
-
Object
- Object
- Taskmeister::TaskList
- Defined in:
- lib/taskmeister/task_list.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add(task) ⇒ Object
- #complete(short_id) ⇒ Object
- #dirty? ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(tasks, file_path) ⇒ TaskList
constructor
A new instance of TaskList.
- #markdown_for(short_id) ⇒ Object
- #replace(short_id, new_text) ⇒ Object
- #tasks ⇒ Object
- #to_short_list ⇒ Object
Constructor Details
#initialize(tasks, file_path) ⇒ TaskList
Returns a new instance of TaskList.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/taskmeister/task_list.rb', line 5 def initialize(tasks, file_path) @file_path = file_path @hash = {} tasks.each do |t| add(t) end @dirty = false end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
3 4 5 |
# File 'lib/taskmeister/task_list.rb', line 3 def file_path @file_path end |
Instance Method Details
#[](key) ⇒ Object
29 30 31 |
# File 'lib/taskmeister/task_list.rb', line 29 def [](key) @hash[key] end |
#add(task) ⇒ Object
41 42 43 44 45 |
# File 'lib/taskmeister/task_list.rb', line 41 def add(task) prefix = assign_short_code_to_task(task) @hash[prefix] = task @dirty = true end |
#complete(short_id) ⇒ Object
47 48 49 50 |
# File 'lib/taskmeister/task_list.rb', line 47 def complete(short_id) removed_val = @hash.delete(short_id) @dirty = true if removed_val end |
#dirty? ⇒ Boolean
37 38 39 |
# File 'lib/taskmeister/task_list.rb', line 37 def dirty? @dirty end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/taskmeister/task_list.rb', line 33 def empty? @hash.empty? end |
#markdown_for(short_id) ⇒ Object
60 61 62 63 64 |
# File 'lib/taskmeister/task_list.rb', line 60 def markdown_for(short_id) return [] unless @hash.has_key?(short_id) self[short_id].to_markdown end |
#replace(short_id, new_text) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/taskmeister/task_list.rb', line 52 def replace(short_id, new_text) task = self[short_id] return unless task @hash[short_id] = Task.new(new_text, task.id, task.notes) @dirty = true end |
#tasks ⇒ Object
25 26 27 |
# File 'lib/taskmeister/task_list.rb', line 25 def tasks @hash.values end |
#to_short_list ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/taskmeister/task_list.rb', line 17 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 |