Module: IceCubeEx::Validations::DayCycleInterval

Included in:
DayCycleRule
Defined in:
lib/ice_cube_ex/validations/day_cycle_interval.rb

Defined Under Namespace

Classes: Validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ruleObject

Returns the value of attribute rule.



4
5
6
# File 'lib/ice_cube_ex/validations/day_cycle_interval.rb', line 4

def rule
  @rule
end

Instance Method Details

#cycle(cycle, skip) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ice_cube_ex/validations/day_cycle_interval.rb', line 6

def cycle(cycle, skip)
  @interval = 1
  @skip     = normalize(skip)
  @cycle    = normalize(cycle)

  unless @skip < @cycle
    raise ArgumentError, "we can't skip more days than the number of "   \
                         "days in the cycle, so skip has to be a value " \
                         "bellow cycle"
  end

  @acceptable_cycle_percentage = \
    (((@cycle - @skip).to_f / @cycle.to_f) * 100).to_i
  replace_validations_for \
    :interval, [Validation.new(@interval, @cycle, @skip)]
  clobber_base_validations(:wday, :day)
  self
end