Class: Syctask::Task
Overview
A Task is the basic element of the task list and holds all information about a task.
Instance Attribute Summary collapse
-
#creation_date ⇒ Object
readonly
Creation date.
-
#dir ⇒ Object
Directory where the file of the task is located.
-
#done_date ⇒ Object
readonly
Done date.
-
#duration ⇒ Object
readonly
Duration specifies the planned time for processing the task.
-
#id ⇒ Object
readonly
ID of the task.
-
#lead_time ⇒ Object
readonly
Lead time is the time this task has been processed.
-
#options ⇒ Object
Holds the options of the task.
-
#remaining ⇒ Object
readonly
Remaining time is the duration subtracted by the lead time since last plan.
-
#title ⇒ Object
readonly
Title of the class.
-
#update_date ⇒ Object
readonly
Update date.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares this Task to the other task and compares them regarding the ID and the dir.
-
#==(other) ⇒ Object
Compares this task with another task regarding id and dir.
-
#done(note = "") ⇒ Object
Marks the task as done.
-
#done? ⇒ Boolean
Checks if this task is done.
-
#initialize(options = {}, title, id) ⇒ Task
constructor
Creates a new task.
-
#matches?(filter = {}) ⇒ Boolean
Compares the provided elements in the filter with the correspondent elements in the task.
-
#print_csv ⇒ Object
Prints the task as a CSV.
-
#print_pretty(long = false) ⇒ Object
Prints the task in a formatted way eather all values when long is true or only id, title, prio, follow-up and due date.
-
#set_duration(duration) ⇒ Object
Sets the duration that this task is planned for processing.
-
#today? ⇒ Boolean
Checks if task is scheduled for today.
-
#tracked? ⇒ Boolean
Checks whether the task is currently tracked.
-
#update(options) ⇒ Object
Updates the task with new values.
-
#update? ⇒ Boolean
Checks whether this task has been updated.
-
#update_lead_time(lead_time) ⇒ Object
Updates the lead time.
Constructor Details
#initialize(options = {}, title, id) ⇒ Task
Creates a new task. If the options contain a note than the current date and time is added.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/syctask/task.rb', line 46 def initialize(={}, title, id) @creation_date = Time.now.strftime("%Y-%m-%d - %H:%M:%S") @title = title = [:note] = "#{@creation_date}\n#{@options[:note]}\n" if [:note] if [:follow_up] or [:due_date] @duration = 2 * 15 * 60 @remaining = 2 * 15 * 60 else @duration = 0 @remaining = 0 end @id = id end |
Instance Attribute Details
#creation_date ⇒ Object (readonly)
Creation date
36 37 38 |
# File 'lib/syctask/task.rb', line 36 def creation_date @creation_date end |
#dir ⇒ Object
Directory where the file of the task is located
42 43 44 |
# File 'lib/syctask/task.rb', line 42 def dir @dir end |
#done_date ⇒ Object (readonly)
Done date
40 41 42 |
# File 'lib/syctask/task.rb', line 40 def done_date @done_date end |
#duration ⇒ Object (readonly)
Duration specifies the planned time for processing the task
30 31 32 |
# File 'lib/syctask/task.rb', line 30 def duration @duration end |
#id ⇒ Object (readonly)
ID of the task
28 29 30 |
# File 'lib/syctask/task.rb', line 28 def id @id end |
#lead_time ⇒ Object (readonly)
Lead time is the time this task has been processed
34 35 36 |
# File 'lib/syctask/task.rb', line 34 def lead_time @lead_time end |
#options ⇒ Object
Holds the options of the task. Options are
-
description - additional information about the task
-
follow_up - follow-up date of the task
-
due - due date of the task
-
prio - priority of the task
-
note - information about the progress or state of the task
-
tags - can be used to search for tasks that belong to a certain category
24 25 26 |
# File 'lib/syctask/task.rb', line 24 def end |
#remaining ⇒ Object (readonly)
Remaining time is the duration subtracted by the lead time since last plan
32 33 34 |
# File 'lib/syctask/task.rb', line 32 def remaining @remaining end |
#title ⇒ Object (readonly)
Title of the class
26 27 28 |
# File 'lib/syctask/task.rb', line 26 def title @title end |
#update_date ⇒ Object (readonly)
Update date
38 39 40 |
# File 'lib/syctask/task.rb', line 38 def update_date @update_date end |
Instance Method Details
#<=>(other) ⇒ Object
Compares this Task to the other task and compares them regarding the ID and the dir. If ID is equal then dir is compared
70 71 72 73 74 75 76 77 |
# File 'lib/syctask/task.rb', line 70 def <=>(other) id_compare = @id.to_i <=> other.id.to_i if id_compare == 0 @dir <=> other.dir else id_compare end end |
#==(other) ⇒ Object
Compares this task with another task regarding id and dir. If both are equal true is returned otherwise false
64 65 66 |
# File 'lib/syctask/task.rb', line 64 def ==(other) @id == other.id and @dir == other.dir end |
#done(note = "") ⇒ Object
Marks the task as done. When done than the done date is set. Optionally a note can be provided.
138 139 140 141 142 143 144 |
# File 'lib/syctask/task.rb', line 138 def done(note="") @done_date = Time.now.strftime("%Y-%m-%d - %H:%M:%S") if note [:note] = "#{@done_date}\n#{note}\n#{@options[:note]}" end Syctask::log_task("done", self) end |
#done? ⇒ Boolean
Checks if this task is done. Returns true if done otherwise false
147 148 149 |
# File 'lib/syctask/task.rb', line 147 def done? !@done_date.nil? end |
#matches?(filter = {}) ⇒ Boolean
Compares the provided elements in the filter with the correspondent elements in the task. When all comparissons match than true is returned. If one comparisson does not match false is returned. If filter is empty than true is returned. The values can be compared regarding <, =, > or whether the task’s value is part of a list of provided values. It is also possible to provide a regex as a filter. Following comparissons are available Value Compare :title regex :description regex :id contains, <|=|> no operator same as = :prio contains, <|=|> no operator same as = :tags contains, regex :follow_up <|=|> :due <|=|>
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/syctask/task.rb', line 183 def matches?(filter = {}) return true if filter.empty? evaluator = Evaluator.new filter.each do |key, value| matches = false case key when :title, :t matches = evaluator.matches?(@title, value) when :description matches = evaluator.matches?([:description], value) when :id, :i, "id", "i" matches = (evaluator.includes?(@id, value) or evaluator.compare_numbers(@id, value)) when :prio, :p matches = (evaluator.includes?([:prio], value) or evaluator.compare([:prio], value)) when :tags matches = evaluator.matches?([:tags], value) when :follow_up, :f, :d, :due_date matches = evaluator.compare_dates([key], value) end return false unless matches end true end |
#print_csv ⇒ Object
Prints the task as a CSV
216 217 218 |
# File 'lib/syctask/task.rb', line 216 def print_csv STDOUT.puts(csv_string) end |
#print_pretty(long = false) ⇒ Object
Prints the task in a formatted way eather all values when long is true or only id, title, prio, follow-up and due date.
211 212 213 |
# File 'lib/syctask/task.rb', line 211 def print_pretty(long=false) pretty_string(long) end |
#set_duration(duration) ⇒ Object
Sets the duration that this task is planned for processing. Assigns to remaining the duration time
116 117 118 119 |
# File 'lib/syctask/task.rb', line 116 def set_duration(duration) @duration = duration @remaining = duration end |
#today? ⇒ Boolean
Checks if task is scheduled for today. Returns true if follow up or due date is today otherwise false.
153 154 155 156 157 158 |
# File 'lib/syctask/task.rb', line 153 def today? evaluator = Evaluator.new today = Time.now.strftime("%Y-%m-%d") evaluator.compare_dates([:follow_up], today) or \ evaluator.compare_dates([:due_date], today) end |
#tracked? ⇒ Boolean
Checks whether the task is currently tracked. Returns true if so otherwise false
162 163 164 165 166 |
# File 'lib/syctask/task.rb', line 162 def tracked? tracker = Syctask::TaskTracker.new task = tracker.tracked_task task.nil? ? false : task == self end |
#update(options) ⇒ Object
Updates the task with new values. Except for note and tags which are supplemented with the new values and not overridden.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/syctask/task.rb', line 81 def update() @update_date = Time.now.strftime("%Y-%m-%d - %H:%M:%S") if [:duration] set_duration(.delete(:duration).to_i * 15 * 60) elsif [:follow_up] or [:due_date] set_duration(2 * 15 * 60) if @duration.nil? end .keys.each do |key| new_value = [key] case key when :note new_value = "#{@update_date}\n#{new_value}\n#{@options[key]}" when :tags unless [key].nil? if [key].include? new_value new_value = [key] else new_value = "#{@options[key]},#{new_value}" end end end [key] = new_value end end |
#update? ⇒ Boolean
Checks whether this task has been updated. Returns true if updated otherwise false
110 111 112 |
# File 'lib/syctask/task.rb', line 110 def update? !@updated_date.nil? end |
#update_lead_time(lead_time) ⇒ Object
Updates the lead time. Adds the lead time to @lead_time and calculates
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/syctask/task.rb', line 123 def update_lead_time(lead_time) if @lead_time @lead_time += lead_time else @lead_time = lead_time end if @remaining @remaining -= lead_time else @remaining = @duration.to_i - lead_time end end |