Class: Biz::Interval
- Inherits:
-
Object
- Object
- Biz::Interval
- Defined in:
- lib/biz/interval.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#time_zone ⇒ Object
readonly
Returns the value of attribute time_zone.
Instance Method Summary collapse
- #contains?(time) ⇒ Boolean
- #endpoints ⇒ Object
-
#initialize(start_time, end_time, time_zone) ⇒ Interval
constructor
A new instance of Interval.
- #to_time_segment(week) ⇒ Object
Constructor Details
#initialize(start_time, end_time, time_zone) ⇒ Interval
Returns a new instance of Interval.
10 11 12 13 14 |
# File 'lib/biz/interval.rb', line 10 def initialize(start_time, end_time, time_zone) @start_time = start_time @end_time = end_time @time_zone = time_zone end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
6 7 8 |
# File 'lib/biz/interval.rb', line 6 def end_time @end_time end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
6 7 8 |
# File 'lib/biz/interval.rb', line 6 def start_time @start_time end |
#time_zone ⇒ Object (readonly)
Returns the value of attribute time_zone.
6 7 8 |
# File 'lib/biz/interval.rb', line 6 def time_zone @time_zone end |
Instance Method Details
#contains?(time) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/biz/interval.rb', line 20 def contains?(time) (start_time...end_time).cover?( WeekTime.from_time(Time.new(time_zone).local(time)) ) end |
#endpoints ⇒ Object
16 17 18 |
# File 'lib/biz/interval.rb', line 16 def endpoints [start_time, end_time] end |
#to_time_segment(week) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/biz/interval.rb', line 26 def to_time_segment(week) TimeSegment.new( *endpoints.map { |endpoint| Time.new(time_zone).during_week(week, endpoint) } ) end |