Class: Nucleo::Models::MetricPeriod

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nucleo/models/metric_period.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Nucleo::Models::MetricPeriod

Returns an instance of the Metric Period domain model

Parameters:

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


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

Returns:

  • (Boolean)


52
53
54
# File 'lib/nucleo/models/metric_period.rb', line 52

def current?
  'current' == self.period_name
end

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

#dimensionString

Returns the dimension

Returns:

  • (String)


38
39
40
# File 'lib/nucleo/models/metric_period.rb', line 38

def dimension
  @attributes['dimension']
end

#metricString

Returns the type of the metric

Returns:

  • (String)


31
32
33
# File 'lib/nucleo/models/metric_period.rb', line 31

def metric
  @attributes['metric']
end

#period_nameString

Returns the name of the period

Returns:

  • (String)


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

Returns:

  • (Boolean)


59
60
61
# File 'lib/nucleo/models/metric_period.rb', line 59

def prior?
  'prior' == self.period_name
end

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

Returns:

  • (Boolean)


87
88
89
# File 'lib/nucleo/models/metric_period.rb', line 87

def rows?
  self.rows.any?
end

#totalsInteger

Returns the totals for this type of metric

Returns:

  • (Integer)


66
67
68
# File 'lib/nucleo/models/metric_period.rb', line 66

def totals
  totals_hash.fetch(self.metric, 0).to_i
end