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.



17
18
19
# File 'lib/ice_cube/validations/day_of_year.rb', line 17

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



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

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

#build_ical(builder) ⇒ Object



44
45
46
# File 'lib/ice_cube/validations/day_of_year.rb', line 44

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

#build_s(builder) ⇒ Object



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

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

#dst_adjust?Boolean

Returns:

  • (Boolean)


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

def dst_adjust?
  true
end

#typeObject



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

def type
  :day
end

#validate(step_time, start_time) ⇒ Object



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

def validate(step_time, start_time)
  days_in_year = TimeUtil.days_in_year(step_time)
  yday = (day < 0) ? day + days_in_year + 1 : day
  offset = yday - step_time.yday
  (offset >= 0) ? offset : offset + days_in_year
end