Class: TurbaChronos::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/turba_chronos/day.rb

Defined Under Namespace

Classes: TempTimerange

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(beginning_of_day, periods, timeranges_for_days) ⇒ Day

Returns a new instance of Day.



4
5
6
7
8
# File 'lib/turba_chronos/day.rb', line 4

def initialize(beginning_of_day, periods, timeranges_for_days)
  @beginning_of_day = beginning_of_day.to_time
  @rules = get_rules_for_day(periods)
  @timeranges_for_days = timeranges_for_days
end

Instance Attribute Details

#beginning_of_dayObject (readonly)

Returns the value of attribute beginning_of_day.



3
4
5
# File 'lib/turba_chronos/day.rb', line 3

def beginning_of_day
  @beginning_of_day
end

Instance Method Details

#current_timeframeObject



22
23
24
25
26
27
28
29
# File 'lib/turba_chronos/day.rb', line 22

def current_timeframe
  get_timeframes(:timeranges).each do |timeframe|
    return timeframe if timeframe.timerange === TurbaChronos.current_numeric_time
  end

  range = (Time.now.utc.beginning_of_hour.strftime("%k%M").to_i..Time.now.utc.end_of_hour.strftime("%k%M").to_i)
  return TempTimerange.new(range, 6)
end

#current_timeframe_indexObject



31
32
33
# File 'lib/turba_chronos/day.rb', line 31

def current_timeframe_index
  timeframes.map {|x| x.timerange}.index(current_timeframe.timerange)
end

#dateObject



10
11
12
# File 'lib/turba_chronos/day.rb', line 10

def date
  @date ||= @beginning_of_day.to_datetime.iso8601
end

#opened?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/turba_chronos/day.rb', line 14

def opened?
  current_timeframe.level != 6
end

#timeframesObject



18
19
20
# File 'lib/turba_chronos/day.rb', line 18

def timeframes
  @timeframes ||= get_timeframes(:business_timeranges)
end