Class: Nucleo::Models::MetricPeriods

Inherits:
Object
  • Object
show all
Defined in:
lib/nucleo/models/metric_periods.rb

Instance Method Summary collapse

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.

Parameters:

  • attributes (Hash) (defaults to: {})


15
16
17
# File 'lib/nucleo/models/metric_periods.rb', line 15

def initialize(attributes={})
  @attributes = attributes
end

Instance Method Details

#current_periodNucleo::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

#dimensionString

Returns the dimension

Returns:

  • (String)


36
37
38
# File 'lib/nucleo/models/metric_periods.rb', line 36

def dimension
  @attributes['dimension']
end

#metricString

Returns the type of the metric

Returns:

  • (String)


29
30
31
# File 'lib/nucleo/models/metric_periods.rb', line 29

def metric
  @attributes['metric']
end

#periods_comparisonsArray

Returns a metric periods comparisons collection domain model

Returns:

  • (Array)


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_periodNucleo::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

#totalsNucleo::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

#typeString

Returns the type of metric for period

Returns:

  • (String)


22
23
24
# File 'lib/nucleo/models/metric_periods.rb', line 22

def type
  @attributes['type']
end