Class: Spree::Report::TimedObservation

Inherits:
Observation show all
Extended by:
Forwardable
Defined in:
app/reports/spree/report/timed_observation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Observation

build_from_hash, build_from_list, observation_fields

Constructor Details

#initializeTimedObservation

Returns a new instance of TimedObservation.



9
10
11
12
# File 'app/reports/spree/report/timed_observation.rb', line 9

def initialize
  super
  self.hour = 0
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



5
6
7
# File 'app/reports/spree/report/timed_observation.rb', line 5

def date
  @date
end

#hourObject

Returns the value of attribute hour.



5
6
7
# File 'app/reports/spree/report/timed_observation.rb', line 5

def hour
  @hour
end

#reportable_keysObject

Returns the value of attribute reportable_keys.



5
6
7
# File 'app/reports/spree/report/timed_observation.rb', line 5

def reportable_keys
  @reportable_keys
end

Instance Method Details

#day_nameObject



39
40
41
# File 'app/reports/spree/report/timed_observation.rb', line 39

def day_name
  "#{ day } #{ month_name }"
end

#describes?(result, time_scale) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/reports/spree/report/timed_observation.rb', line 14

def describes?(result, time_scale)
  case time_scale
  when :hourly
    result['hour'] == hour && result['day'] == day
  when :daily
    result['day'] == day && result['month'] == month
  when :monthly
    result['month'] == month && result['year'] == year
  when :yearly
    result['year'] == year
  end
end

#hour_nameObject



31
32
33
34
35
36
37
# File 'app/reports/spree/report/timed_observation.rb', line 31

def hour_name
  if hour == 23
    return "23:00 - 00:00"
  else
    return "#{ hour }:00 - #{ hour + 1 }:00"
  end
end

#month_nameObject



27
28
29
# File 'app/reports/spree/report/timed_observation.rb', line 27

def month_name
  Date::MONTHNAMES[month]
end

#to_hObject



43
44
45
# File 'app/reports/spree/report/timed_observation.rb', line 43

def to_h
  super.merge({day_name: day_name, month_name: month_name, year: year, hour_name: hour_name})
end