Class: IceCube::Validations::DayOfYear::Validation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(day) ⇒ Validation

Returns a new instance of Validation.



23
24
25
# File 'lib/ice_cube/validations/day_of_year.rb', line 23

def initialize(day)
  @day = day
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



15
16
17
# File 'lib/ice_cube/validations/day_of_year.rb', line 15

def day
  @day
end

Instance Method Details

#build_hash(builder) ⇒ Object



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

def build_hash(builder)
  builder.validations_array(:day_of_year) << day
end

#build_ical(builder) ⇒ Object



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

def build_ical(builder)
  builder['BYYEARDAY'] << day
end

#build_s(builder) ⇒ Object



31
32
33
# File 'lib/ice_cube/validations/day_of_year.rb', line 31

def build_s(builder)
  builder.piece(:day_of_year) << StringBuilder.nice_number(day)
end

#typeObject



27
28
29
# File 'lib/ice_cube/validations/day_of_year.rb', line 27

def type
  :day
end

#validate(time, schedule) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/ice_cube/validations/day_of_year.rb', line 43

def validate(time, schedule)
  days_in_year = TimeUtil.days_in_year(time)
  the_day = day < 0 ? day + days_in_year : day
  # compute the diff
  diff = the_day - time.yday
  diff >= 0 ? diff : diff + days_in_year
end