Class: TurbaChronos::Rule

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

Defined Under Namespace

Classes: TextTime

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, business_hours = false) ⇒ Rule

Returns a new instance of Rule.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/turba_chronos/rule.rb', line 8

def initialize(rule, business_hours=false)
  @business_hours = business_hours
  if rule.is_a?(Array)
    @wdays = rule[2..-2]
    self.start_time = rule[0]
    self.end_time = rule[1]
  else
    @wdays = [rule[:mo], rule[:tu], rule[:we], rule[:th], rule[:fr], rule[:sa], rule[:su]]
    self.start_time = rule[:s]
    self.end_time = rule[:e]
  end
end

Instance Attribute Details

#business_hoursObject

Returns the value of attribute business_hours.



6
7
8
# File 'lib/turba_chronos/rule.rb', line 6

def business_hours
  @business_hours
end

#end_timeObject

Returns the value of attribute end_time.



4
5
6
# File 'lib/turba_chronos/rule.rb', line 4

def end_time
  @end_time
end

#rangeObject

Returns the value of attribute range.



5
6
7
# File 'lib/turba_chronos/rule.rb', line 5

def range
  @range
end

#start_timeObject

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

Instance Method Details

#maxObject



25
26
27
# File 'lib/turba_chronos/rule.rb', line 25

def max
  range.max
end

#minObject



21
22
23
# File 'lib/turba_chronos/rule.rb', line 21

def min
  range.min
end

#wdaysObject



41
42
43
# File 'lib/turba_chronos/rule.rb', line 41

def wdays
  @cachewdays ||= @wdays.map(&:to_i)
end