Class: IceCube::Validations::YearlyInterval::Validation
- Inherits:
-
Object
- Object
- IceCube::Validations::YearlyInterval::Validation
- Defined in:
- lib/ice_cube/validations/yearly_interval.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Instance Method Summary collapse
- #build_hash(builder) ⇒ Object
- #build_ical(builder) ⇒ Object
- #build_s(builder) ⇒ Object
-
#initialize(interval) ⇒ Validation
constructor
A new instance of Validation.
- #type ⇒ Object
- #validate(time, schedule) ⇒ Object
Constructor Details
#initialize(interval) ⇒ Validation
Returns a new instance of Validation.
33 34 35 |
# File 'lib/ice_cube/validations/yearly_interval.rb', line 33 def initialize(interval) @interval = interval end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
12 13 14 |
# File 'lib/ice_cube/validations/yearly_interval.rb', line 12 def interval @interval end |
Instance Method Details
#build_hash(builder) ⇒ Object
22 23 24 |
# File 'lib/ice_cube/validations/yearly_interval.rb', line 22 def build_hash(builder) builder[:interval] = interval end |
#build_ical(builder) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ice_cube/validations/yearly_interval.rb', line 26 def build_ical(builder) builder['FREQ'] << 'YEARLY' unless interval == 1 builder['INTERVAL'] << interval end end |
#build_s(builder) ⇒ Object
18 19 20 |
# File 'lib/ice_cube/validations/yearly_interval.rb', line 18 def build_s(builder) builder.base = interval == 1 ? 'Yearly' : "Every #{interval} years" end |
#type ⇒ Object
14 15 16 |
# File 'lib/ice_cube/validations/yearly_interval.rb', line 14 def type :year end |
#validate(time, schedule) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/ice_cube/validations/yearly_interval.rb', line 37 def validate(time, schedule) raise ZeroInterval if interval == 0 years_to_start = time.year - schedule.start_time.year unless years_to_start % interval == 0 interval - (years_to_start % interval) end end |