Class: Pomodoro::Formats::Today::TaskList
- Inherits:
-
Object
- Object
- Pomodoro::Formats::Today::TaskList
- Includes:
- Enumerable
- Defined in:
- lib/pomodoro/formats/today/task_list.rb
Instance Attribute Summary collapse
-
#time_frame_list ⇒ Object
readonly
Returns the value of attribute time_frame_list.
Instance Method Summary collapse
- #duration ⇒ Object
- #each(&block) ⇒ Object
- #get_current_time_frame(current_time = Time.now) ⇒ Object
-
#initialize(time_frame_list) ⇒ TaskList
constructor
A new instance of TaskList.
- #save(path) ⇒ Object
-
#to_s ⇒ Object
def has_unfinished_tasks? @time_frame_list.any?(&:has_unfinished_tasks?) end.
Constructor Details
#initialize(time_frame_list) ⇒ TaskList
Returns a new instance of TaskList.
6 7 8 9 10 11 12 13 14 |
# File 'lib/pomodoro/formats/today/task_list.rb', line 6 def initialize(time_frame_list) @time_frame_list = time_frame_list time_frame_list.each do |time_frame| self.define_singleton_method(time_frame.method_name) do time_frame end end end |
Instance Attribute Details
#time_frame_list ⇒ Object (readonly)
Returns the value of attribute time_frame_list.
5 6 7 |
# File 'lib/pomodoro/formats/today/task_list.rb', line 5 def time_frame_list @time_frame_list end |
Instance Method Details
#duration ⇒ Object
29 30 31 |
# File 'lib/pomodoro/formats/today/task_list.rb', line 29 def duration self.time_frame_list.sum { |time_frame| time_frame.duration } end |
#each(&block) ⇒ Object
24 25 26 |
# File 'lib/pomodoro/formats/today/task_list.rb', line 24 def each(&block) @time_frame_list.each(&block) end |
#get_current_time_frame(current_time = Time.now) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/pomodoro/formats/today/task_list.rb', line 16 def get_current_time_frame(current_time = Time.now) @time_frame_list.find do |time_frame| starting_time, closing_time = time_frame.interval starting_time < current_time && (closing_time.nil? || closing_time > current_time) end end |
#save(path) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/pomodoro/formats/today/task_list.rb', line 43 def save(path) data = self.to_s File.open(path, 'w') do |file| file.puts(data) end end |
#to_s ⇒ Object
def has_unfinished_tasks?
@time_frame_list.any?(&:has_unfinished_tasks?)
end
37 38 39 40 41 |
# File 'lib/pomodoro/formats/today/task_list.rb', line 37 def to_s self.time_frame_list.reduce(nil) do |buffer, time_frame| buffer ? "#{buffer}\n\n#{time_frame.to_s}" : "#{time_frame.to_s}" end end |