Class: Decidim::MetricMeasure
- Inherits:
-
Object
- Object
- Decidim::MetricMeasure
- Defined in:
- app/queries/decidim/metric_measure.rb
Overview
This class executes some measures related to Metrics, and return its results
- day: Date object
- resource: Object used to make measurements. Object class is dependent within each measure
Instance Method Summary collapse
-
#calculate ⇒ Object
this method must be overwritten for each Measure class.
-
#initialize(day, resource) ⇒ MetricMeasure
constructor
A new instance of MetricMeasure.
- #valid? ⇒ Boolean
Constructor Details
#initialize(day, resource) ⇒ MetricMeasure
Returns a new instance of MetricMeasure.
9 10 11 12 13 14 15 |
# File 'app/queries/decidim/metric_measure.rb', line 9 def initialize(day, resource) @day = day.try(:to_date) || Time.zone.yesterday raise ArgumentError, "[ERROR] Malformed `day` argument. Format must be `YYYY-MM-DD` and in the past" if @day > Time.zone.today @day ||= Time.zone.yesterday @resource = resource end |
Instance Method Details
#calculate ⇒ Object
this method must be overwritten for each Measure class
22 23 24 |
# File 'app/queries/decidim/metric_measure.rb', line 22 def calculate raise StandardError, "Not implemented" end |
#valid? ⇒ Boolean
17 18 19 |
# File 'app/queries/decidim/metric_measure.rb', line 17 def valid? @day.present? && @resource.present? end |