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.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/taskmeister/task_list.rb', line 7 def initialize(tasks, file_path) @file_path = Pathname.new file_path @shortIdToTask = {} tasks.each do |t| add(t) end @dirty = false end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/taskmeister/task_list.rb', line 5 def file_path @file_path end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/taskmeister/task_list.rb', line 31 def [](key) @shortIdToTask[key] end |
#add(task) ⇒ Object
43 44 45 46 47 |
# File 'lib/taskmeister/task_list.rb', line 43 def add(task) prefix = assign_short_code_to_task(task) @shortIdToTask[prefix] = task @dirty = true end |
#complete(short_id) ⇒ Object
49 50 51 52 |
# File 'lib/taskmeister/task_list.rb', line 49 def complete(short_id) removed_val = @shortIdToTask.delete(short_id) @dirty = true if removed_val end |
#dirty? ⇒ Boolean
39 40 41 |
# File 'lib/taskmeister/task_list.rb', line 39 def dirty? @dirty end |
#empty? ⇒ Boolean
35 36 37 |
# File 'lib/taskmeister/task_list.rb', line 35 def empty? @shortIdToTask.empty? end |
#markdown_for(short_id) ⇒ Object
62 63 64 65 66 |
# File 'lib/taskmeister/task_list.rb', line 62 def markdown_for(short_id) return [] unless @shortIdToTask.has_key?(short_id) self[short_id].to_markdown end |
#replace(short_id, new_text) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/taskmeister/task_list.rb', line 54 def replace(short_id, new_text) task = self[short_id] return unless task @shortIdToTask[short_id] = Task.new(new_text, task.id, task.notes) @dirty = true end |
#tasks ⇒ Object
27 28 29 |
# File 'lib/taskmeister/task_list.rb', line 27 def tasks @shortIdToTask.values end |
#to_short_list ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/taskmeister/task_list.rb', line 19 def to_short_list longest_id = @shortIdToTask.keys.max_by(&:length) @shortIdToTask.map { |id, task| marker = task.notes? ? " »" : "" "%-#{longest_id.length}s - %s%s" % [id, task.text, marker] } end |