Class: PlantWatchdog::DayOfYearConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/plantwatchdog/data.rb

Instance Method Summary collapse

Constructor Details

#initialize(year, days_of_year) ⇒ DayOfYearConverter

Returns a new instance of DayOfYearConverter.



103
104
105
106
107
108
# File 'lib/plantwatchdog/data.rb', line 103

def initialize(year, days_of_year)
  @year = year
  start = Time.utc(year, 1, 1)
  @days_of_year = days_of_year.collect { |d| secs_of_year = (d - 1) * 3600*24 ; start + secs_of_year }
  logger.debug "DayOfYearConverter: Added #{@days_of_year.size} days for year #{@year}"
end

Instance Method Details

#days(month) ⇒ Object



117
118
119
120
# File 'lib/plantwatchdog/data.rb', line 117

def days(month)
  logger.debug "DayOfYearConverter: Searching days for #{month} in #{@year}, #{self}"
  @days_of_year.select{|d| d.month == month}.collect{|d| d.day}
end

#loggerObject



122
123
124
# File 'lib/plantwatchdog/data.rb', line 122

def logger
  return ActiveRecord::Base.logger
end

#monthsObject



110
111
112
113
114
115
# File 'lib/plantwatchdog/data.rb', line 110

def months
  logger.debug "DayOfYearConverter: Searching for months in #{@year}, #{self}"
  months = @days_of_year.collect{|d| d.month }
  months.uniq!
  months
end