Sha256: dcb7f7b7538d25fb4dfdb3af502a4aec75e254fb824454263f8d5e2cc0a5a9d5

Contents?: true

Size: 922 Bytes

Versions: 58

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # 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
  class MetricMeasure
    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

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

    # this method must be overwritten for each Measure class
    def calculate
      raise StandardError, "Not implemented"
    end

    private

    def start_time
      @start_time ||= @day.beginning_of_day
    end

    def end_time
      @end_time ||= @day.end_of_day
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/queries/decidim/metric_measure.rb
decidim-core-0.27.9 app/queries/decidim/metric_measure.rb
decidim-core-0.28.3 app/queries/decidim/metric_measure.rb
decidim-core-0.27.8 app/queries/decidim/metric_measure.rb
decidim-core-0.28.2 app/queries/decidim/metric_measure.rb
decidim-core-0.27.7 app/queries/decidim/metric_measure.rb
decidim-core-0.28.1 app/queries/decidim/metric_measure.rb
decidim-core-0.27.6 app/queries/decidim/metric_measure.rb
decidim-core-0.26.10 app/queries/decidim/metric_measure.rb
decidim-core-0.26.9 app/queries/decidim/metric_measure.rb
decidim-core-0.28.0 app/queries/decidim/metric_measure.rb
decidim-core-0.27.5 app/queries/decidim/metric_measure.rb
decidim-core-0.28.0.rc5 app/queries/decidim/metric_measure.rb
decidim-core-0.28.0.rc4 app/queries/decidim/metric_measure.rb
decidim-core-0.26.8 app/queries/decidim/metric_measure.rb
decidim-core-0.27.4 app/queries/decidim/metric_measure.rb
decidim-core-0.27.3 app/queries/decidim/metric_measure.rb
decidim-core-0.26.7 app/queries/decidim/metric_measure.rb
decidim-core-0.26.5 app/queries/decidim/metric_measure.rb
decidim-core-0.27.2 app/queries/decidim/metric_measure.rb