Class: Decidim::MetricMeasure

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/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 dependant within each measure

Instance Method Summary collapse

Constructor Details

#initialize(day, resource) ⇒ MetricMeasure

Returns a new instance of MetricMeasure.

Raises:

  • (ArgumentError)

9
10
11
12
13
14
15
# File 'decidim-core/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

#calculateObject

this method must be overwritten for each Measure class

Raises:

  • (StandardError)

22
23
24
# File 'decidim-core/app/queries/decidim/metric_measure.rb', line 22

def calculate
  raise StandardError, "Not implemented"
end

#valid?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'decidim-core/app/queries/decidim/metric_measure.rb', line 17

def valid?
  @day.present? && @resource.present?
end