Class: IceCube::Validations::Count::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/ice_cube/validations/count.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count, rule) ⇒ Validation

Returns a new instance of Validation.



20
21
22
23
# File 'lib/ice_cube/validations/count.rb', line 20

def initialize(count, rule)
  @count = count
  @rule = rule
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



18
19
20
# File 'lib/ice_cube/validations/count.rb', line 18

def count
  @count
end

#ruleObject (readonly)

Returns the value of attribute rule.



18
19
20
# File 'lib/ice_cube/validations/count.rb', line 18

def rule
  @rule
end

Instance Method Details

#build_hash(builder) ⇒ Object



39
40
41
# File 'lib/ice_cube/validations/count.rb', line 39

def build_hash(builder)
  builder[:count] = count
end

#build_ical(builder) ⇒ Object



43
44
45
# File 'lib/ice_cube/validations/count.rb', line 43

def build_ical(builder)
  builder['COUNT'] << count
end

#build_s(builder) ⇒ Object



35
36
37
# File 'lib/ice_cube/validations/count.rb', line 35

def build_s(builder)
  builder.piece(:count) << count
end

#typeObject



25
26
27
# File 'lib/ice_cube/validations/count.rb', line 25

def type
  :dealbreaker
end

#validate(time, schedule) ⇒ Object



29
30
31
32
33
# File 'lib/ice_cube/validations/count.rb', line 29

def validate(time, schedule)
  if rule.uses && rule.uses >= count
    raise CountExceeded
  end
end