Class: Pomodoro::Formats::Today::TimeFrame
- Inherits:
-
Object
- Object
- Pomodoro::Formats::Today::TimeFrame
- Includes:
- Enumerable
- Defined in:
- lib/pomodoro/formats/today/time_frame.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #active_task ⇒ Object
- #create_task(header, duration = nil, tags = Array.new) ⇒ Object
- #duration ⇒ Object
- #each(&block) ⇒ Object
- #first_unstarted_task ⇒ Object
-
#initialize(header:, start_time: nil, end_time: nil, task_list: Array.new, **shit) ⇒ TimeFrame
constructor
A new instance of TimeFrame.
- #method_name ⇒ Object
- #remaining_duration ⇒ Object
- #to_s ⇒ Object
- #unshift_task(*args) ⇒ Object
Constructor Details
#initialize(header:, start_time: nil, end_time: nil, task_list: Array.new, **shit) ⇒ TimeFrame
Returns a new instance of TimeFrame.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 10 def initialize(header:, start_time: nil, end_time: nil, task_list: Array.new, **shit) # tag, interval_from, interval_to, options = Hash.new @name, @tag, @options = header, nil, {} @interval = [start_time, end_time] @start_time, @end_time = start_time, end_time @header = header # @interval = [interval_from && Hour.parse(interval_from), interval_to && Hour.parse(interval_to)] @tasks = task_list # if @options.has_key?(:writeable) && ! @options[:writeable] # @tasks.freeze # end unless ( = .keys - ALLOWED_OPTIONS).empty? raise ArgumentError.new("Unrecognised options: #{.inspect}") end end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
9 10 11 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 9 def end_time @end_time end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
9 10 11 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 9 def header @header end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
8 9 10 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8 def interval @interval end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8 def @options end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
9 10 11 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 9 def start_time @start_time end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
8 9 10 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8 def tasks @tasks end |
Instance Method Details
#active_task ⇒ Object
64 65 66 67 68 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 64 def active_task self.tasks.find do |task| task.in_progress? end end |
#create_task(header, duration = nil, tags = Array.new) ⇒ Object
28 29 30 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 28 def create_task(header, duration = nil, = Array.new) @tasks << Task.new(header: header, tags: ) end |
#duration ⇒ Object
87 88 89 90 91 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 87 def duration self.tasks.reduce(0) do |sum, task| (task.finished? && task.duration) ? sum + task.duration : sum end end |
#each(&block) ⇒ Object
81 82 83 84 85 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 81 def each(&block) @tasks.each do |task| block.call(task) end end |
#first_unstarted_task ⇒ Object
70 71 72 73 74 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 70 def first_unstarted_task self.tasks.find do |task| task.unstarted? end end |
#method_name ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 56 def method_name if @name @name.downcase.tr(' ', '_').to_sym else :default end end |
#remaining_duration ⇒ Object
76 77 78 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 76 def remaining_duration @interval[1] && (@interval[1] - Hour.now) end |
#to_s ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/pomodoro/formats/today/time_frame.rb', line 48 def to_s if @tasks.empty? self.header else ["#{self.header}", self.tasks.map(&:to_s)].join("\n") end end |