class Nucleo::Models::MetricPeriod
Public Class Methods
new(attributes={})
click to toggle source
Returns an instance of the Metric
Period domain model
@param attributes [Hash]
@return [Nucleo::Models::MetricPeriod]
# File lib/nucleo/models/metric_period.rb, line 13 def initialize(attributes={}) @attributes = attributes end
Public Instance Methods
<=>(other)
click to toggle source
Implement Comparable
# File lib/nucleo/models/metric_period.rb, line 18 def <=>(other) if self.current? 1 elsif self.prior? 0 else -1 end end
current?()
click to toggle source
Returns true if this is current
@return [Boolean]
# File lib/nucleo/models/metric_period.rb, line 52 def current? 'current' == self.period_name end
date_range()
click to toggle source
Returns the instance of the DateRange
domain model
@return [Nucleo::Models::DateRange]
# File lib/nucleo/models/metric_period.rb, line 73 def date_range Nucleo::Models::DateRange.new(@attributes.fetch('date_range', {})) end
dimension()
click to toggle source
Returns the dimension
@return [String]
# File lib/nucleo/models/metric_period.rb, line 38 def dimension @attributes['dimension'] end
metric()
click to toggle source
Returns the type of the metric
@return [String]
# File lib/nucleo/models/metric_period.rb, line 31 def metric @attributes['metric'] end
period_name()
click to toggle source
Returns the name of the period
@return [String]
# File lib/nucleo/models/metric_period.rb, line 45 def period_name @attributes['period_name'] end
prior?()
click to toggle source
Returns true if this is for the prior period
@return [Boolean]
# File lib/nucleo/models/metric_period.rb, line 59 def prior? 'prior' == self.period_name end
rows()
click to toggle source
Returns an instance of the MetricPeriodRows
domain model
@return [Nucleo::Models::MetricPeriodRows]
# File lib/nucleo/models/metric_period.rb, line 80 def rows Nucleo::Models::MetricPeriodRows.new(self.metric, self.dimension, self.period_name, @attributes.fetch('rows', [])) end
rows?()
click to toggle source
Returns true if there are any rows
@return [Boolean]
# File lib/nucleo/models/metric_period.rb, line 87 def rows? self.rows.any? end
totals()
click to toggle source
Returns the totals for this type of metric
@return [Integer]
# File lib/nucleo/models/metric_period.rb, line 66 def totals totals_hash.fetch(self.metric, 0).to_i end
Private Instance Methods
totals_hash()
click to toggle source
# File lib/nucleo/models/metric_period.rb, line 92 def totals_hash @attributes.fetch('totals', {}) end