Class: Nucleo::Models::MetricPeriodRow

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

Instance Method Summary collapse

Constructor Details

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

Returns an instance of the Metric Period Row domain model

Parameters:

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


9
10
11
# File 'lib/nucleo/models/metric_period_row.rb', line 9

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

Instance Method Details

#changeFloat

Returns the change

Returns:

  • (Float)


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

def change
  row[translated_key_name(:change)].to_f
end

#current?Boolean

Returns true if this is the current period

Returns:

  • (Boolean)


48
49
50
# File 'lib/nucleo/models/metric_period_row.rb', line 48

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

#dimensionString

Returns the dimension

Returns:

  • (String)


23
24
25
# File 'lib/nucleo/models/metric_period_row.rb', line 23

def dimension
  @attributes['dimension']
end

#dimension_nameString

Returns the dimension name

Returns:

  • (String)


30
31
32
33
34
35
36
# File 'lib/nucleo/models/metric_period_row.rb', line 30

def dimension_name
  if self.page?
    self.page.title
  else
    row.fetch(self.dimension, '')
  end
end

#metricString

Returns the type of the row

Returns:

  • (String)


16
17
18
# File 'lib/nucleo/models/metric_period_row.rb', line 16

def metric
  @attributes['metric']
end

#pageNucleo::Models::Page

Returns an instance of the Page domain model



62
63
64
65
66
67
68
# File 'lib/nucleo/models/metric_period_row.rb', line 62

def page
  val = row['page']

  return nil if val.nil? || val.empty?

  Nucleo::Models::Page.new(val)
end

#page?Boolean

Returns true if there is a page

Returns:

  • (Boolean)


73
74
75
# File 'lib/nucleo/models/metric_period_row.rb', line 73

def page?
  !self.page.nil?
end

#pct_totalFloat Also known as: percent_total

Returns the percent total

Returns:

  • (Float)


94
95
96
# File 'lib/nucleo/models/metric_period_row.rb', line 94

def pct_total
  row[translated_key_name(:pct_total)].to_f
end

#period_nameString

Returns the period name

Returns:

  • (String)


41
42
43
# File 'lib/nucleo/models/metric_period_row.rb', line 41

def period_name
  @attributes['period_name']
end

#prior?Boolean

Returns true if this is the prior period

Returns:

  • (Boolean)


55
56
57
# File 'lib/nucleo/models/metric_period_row.rb', line 55

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

#rankInteger

Returns the rank

Returns:

  • (Integer)


109
110
111
# File 'lib/nucleo/models/metric_period_row.rb', line 109

def rank
  row[translated_key_name(:rank)].to_i
end

#rank_changeInteger

Returns the rank change

Returns:

  • (Integer)


102
103
104
# File 'lib/nucleo/models/metric_period_row.rb', line 102

def rank_change
  row[translated_key_name(:rank_change)].to_i
end

#valueInteger

Return the value for this metric

Returns:

  • (Integer)


80
81
82
# File 'lib/nucleo/models/metric_period_row.rb', line 80

def value
  row.fetch(self.metric, 0).to_i
end