Class: Blackcal::TimeOfDayRange
- Inherits:
-
Object
- Object
- Blackcal::TimeOfDayRange
- Includes:
- Enumerable
- Defined in:
- lib/blackcal/range/time_of_day_range.rb
Overview
Time of day range
Instance Method Summary collapse
-
#cover?(timestamp) ⇒ Boolean
Returns true if it covers timestamp.
-
#each(resolution: :hour, &block) ⇒ Object
Iterate over range.
-
#finish ⇒ TimeOfDay
Return finish hour.
-
#initialize(start, finish = nil) ⇒ TimeOfDayRange
constructor
Initialize time of day range.
-
#start ⇒ TimeOfDay
Return start hour.
-
#to_a(resolution: :hour) ⇒ Array<Array<Integer>>
Returns range as an array.
Constructor Details
#initialize(start, finish = nil) ⇒ TimeOfDayRange
Initialize time of day range
13 14 15 16 |
# File 'lib/blackcal/range/time_of_day_range.rb', line 13 def initialize(start, finish = nil) @start = start @finish = finish end |
Instance Method Details
#cover?(timestamp) ⇒ Boolean
Returns true if it covers timestamp
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/blackcal/range/time_of_day_range.rb', line 20 def cover?() return false if @start.nil? && @finish.nil? t1 = TimeOfDay.new(.hour, .min) if start == finish t1 == start elsif start > finish t1 <= finish || t1 >= start else t1 >= start && t1 <= finish end end |
#each(resolution: :hour, &block) ⇒ Object
Iterate over range
61 62 63 |
# File 'lib/blackcal/range/time_of_day_range.rb', line 61 def each(resolution: :hour, &block) to_a(resolution: resolution).each(&block) end |
#finish ⇒ TimeOfDay
Return finish hour
41 42 43 |
# File 'lib/blackcal/range/time_of_day_range.rb', line 41 def finish @finish_time ||= to_time_of_day(@finish || 0) end |
#start ⇒ TimeOfDay
Return start hour
35 36 37 |
# File 'lib/blackcal/range/time_of_day_range.rb', line 35 def start @start_time ||= to_time_of_day(@start || 0) end |
#to_a(resolution: :hour) ⇒ Array<Array<Integer>>
Returns range as an array
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/blackcal/range/time_of_day_range.rb', line 48 def to_a(resolution: :hour) return [] if @start.nil? && @finish.nil? if finish < start to_time_array(start, TimeOfDay.new(23), resolution) + to_time_array(TimeOfDay.new(0), finish, resolution) else to_time_array(start, finish, resolution) end end |