Class: Nucleo::Models::MetricPeriod
- Inherits:
-
Object
- Object
- Nucleo::Models::MetricPeriod
- Includes:
- Comparable
- Defined in:
- lib/nucleo/models/metric_period.rb
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Implement Comparable.
-
#current? ⇒ Boolean
Returns true if this is current.
-
#date_range ⇒ Nucleo::Models::DateRange
Returns the instance of the DateRange domain model.
-
#dimension ⇒ String
Returns the dimension.
-
#initialize(attributes = {}) ⇒ Nucleo::Models::MetricPeriod
constructor
Returns an instance of the Metric Period domain model.
-
#metric ⇒ String
Returns the type of the metric.
-
#period_name ⇒ String
Returns the name of the period.
-
#prior? ⇒ Boolean
Returns true if this is for the prior period.
-
#rows ⇒ Nucleo::Models::MetricPeriodRows
Returns an instance of the MetricPeriodRows domain model.
-
#rows? ⇒ Boolean
Returns true if there are any rows.
-
#totals ⇒ Integer
Returns the totals for this type of metric.
Constructor Details
#initialize(attributes = {}) ⇒ Nucleo::Models::MetricPeriod
Returns an instance of the Metric Period domain model
13 14 15 |
# File 'lib/nucleo/models/metric_period.rb', line 13 def initialize(attributes={}) @attributes = attributes end |
Instance Method Details
#<=>(other) ⇒ Object
Implement Comparable
18 19 20 21 22 23 24 25 26 |
# File 'lib/nucleo/models/metric_period.rb', line 18 def <=>(other) if self.current? 1 elsif self.prior? 0 else -1 end end |
#current? ⇒ Boolean
Returns true if this is current
52 53 54 |
# File 'lib/nucleo/models/metric_period.rb', line 52 def current? 'current' == self.period_name end |
#date_range ⇒ Nucleo::Models::DateRange
Returns the instance of the DateRange domain model
73 74 75 |
# File 'lib/nucleo/models/metric_period.rb', line 73 def date_range Nucleo::Models::DateRange.new(@attributes.fetch('date_range', {})) end |
#dimension ⇒ String
Returns the dimension
38 39 40 |
# File 'lib/nucleo/models/metric_period.rb', line 38 def dimension @attributes['dimension'] end |
#metric ⇒ String
Returns the type of the metric
31 32 33 |
# File 'lib/nucleo/models/metric_period.rb', line 31 def metric @attributes['metric'] end |
#period_name ⇒ String
Returns the name of the period
45 46 47 |
# File 'lib/nucleo/models/metric_period.rb', line 45 def period_name @attributes['period_name'] end |
#prior? ⇒ Boolean
Returns true if this is for the prior period
59 60 61 |
# File 'lib/nucleo/models/metric_period.rb', line 59 def prior? 'prior' == self.period_name end |
#rows ⇒ Nucleo::Models::MetricPeriodRows
Returns an instance of the MetricPeriodRows domain model
80 81 82 |
# 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? ⇒ Boolean
Returns true if there are any rows
87 88 89 |
# File 'lib/nucleo/models/metric_period.rb', line 87 def rows? self.rows.any? end |
#totals ⇒ Integer
Returns the totals for this type of metric
66 67 68 |
# File 'lib/nucleo/models/metric_period.rb', line 66 def totals totals_hash.fetch(self.metric, 0).to_i end |