Class: Biz::Interval

Inherits:
Object
  • Object
show all
Defined in:
lib/biz/interval.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_timeObject (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_timeObject (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_zoneObject (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

Returns:

  • (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

#endpointsObject



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