Class: Nucleo::Models::MetricPeriods
- Inherits:
-
Object
- Object
- Nucleo::Models::MetricPeriods
- Defined in:
- lib/nucleo/models/metric_periods.rb
Instance Method Summary collapse
-
#current_period ⇒ Nucleo::Models::MetricPeriod
Returns the metric period.
-
#dimension ⇒ String
Returns the dimension.
-
#initialize(attributes = {}) ⇒ Nucleo::Models::MetricPeriods
constructor
Returns an instance of the Metric Periods domain models.
-
#metric ⇒ String
Returns the type of the metric.
-
#periods_comparisons ⇒ Array
Returns a metric periods comparisons collection domain model.
-
#prior_period ⇒ Nucleo::Models::MetricPeriod
(also: #previous_period)
Returns the prior metric period.
-
#totals ⇒ Nucleo::Models::MetricPeriodTotals
Returns the metric period totals.
-
#type ⇒ String
Returns the type of metric for period.
Constructor Details
#initialize(attributes = {}) ⇒ Nucleo::Models::MetricPeriods
Returns an instance of the Metric Periods domain models
This takes in the ‘totals`, `current_period`, and `prior_period` and wraps their response bodies in specific objects for comparisons.
15 16 17 |
# File 'lib/nucleo/models/metric_periods.rb', line 15 def initialize(attributes={}) @attributes = attributes end |
Instance Method Details
#current_period ⇒ Nucleo::Models::MetricPeriod
Returns the metric period
56 57 58 59 |
# File 'lib/nucleo/models/metric_periods.rb', line 56 def current_period params = @attributes.fetch('current_period', {}).merge!('metric' => self.metric, 'dimension' => self.dimension, 'period_name' => 'current') Nucleo::Models::MetricPeriod.new(params) end |
#dimension ⇒ String
Returns the dimension
36 37 38 |
# File 'lib/nucleo/models/metric_periods.rb', line 36 def dimension @attributes['dimension'] end |
#metric ⇒ String
Returns the type of the metric
29 30 31 |
# File 'lib/nucleo/models/metric_periods.rb', line 29 def metric @attributes['metric'] end |
#periods_comparisons ⇒ Array
Returns a metric periods comparisons collection domain model
73 74 75 |
# File 'lib/nucleo/models/metric_periods.rb', line 73 def periods_comparisons Nucleo::Models::MetricPeriodsComparisons.new(self.current_period, self.prior_period) end |
#prior_period ⇒ Nucleo::Models::MetricPeriod Also known as: previous_period
Returns the prior metric period
64 65 66 67 |
# File 'lib/nucleo/models/metric_periods.rb', line 64 def prior_period params = @attributes.fetch('prior_period', {}).merge!('metric' => self.metric, 'dimension' => self.dimension, 'period_name' => 'prior') Nucleo::Models::MetricPeriod.new(params) end |
#totals ⇒ Nucleo::Models::MetricPeriodTotals
Returns the metric period totals
43 44 45 46 47 48 49 50 51 |
# File 'lib/nucleo/models/metric_periods.rb', line 43 def totals params = { 'metric' => self.metric, 'dimension' => self.dimension, 'totals' => @attributes['totals'] } Nucleo::Models::MetricPeriodsTotals.new(params) end |
#type ⇒ String
Returns the type of metric for period
22 23 24 |
# File 'lib/nucleo/models/metric_periods.rb', line 22 def type @attributes['type'] end |