class Nucleo::Models::MetricPeriodRow

Public Class Methods

new(attributes={}) click to toggle source

Returns an instance of the Metric Period Row domain model

@param attributes [Hash]

@return [Nucleo::Models::MetricPeriodRow]

# File lib/nucleo/models/metric_period_row.rb, line 9
def initialize(attributes={})
  @attributes = attributes
end

Public Instance Methods

change() click to toggle source

Returns the change

@return [Float]

# File lib/nucleo/models/metric_period_row.rb, line 87
def change
  row[translated_key_name(:change)].to_f
end
current?() click to toggle source

Returns true if this is the current period

@return [Boolean]

# File lib/nucleo/models/metric_period_row.rb, line 48
def current?
  'current' == self.period_name
end
dimension() click to toggle source

Returns the dimension

@return [String]

# File lib/nucleo/models/metric_period_row.rb, line 23
def dimension
  @attributes['dimension']
end
dimension_name() click to toggle source

Returns the dimension name

@return [String]

# 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
metric() click to toggle source

Returns the type of the row

@return [String]

# File lib/nucleo/models/metric_period_row.rb, line 16
def metric
  @attributes['metric']
end
page() click to toggle source

Returns an instance of the Page domain model

@return [Nucleo::Models::Page]

# 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?() click to toggle source

Returns true if there is a page

@return [Boolean]

# File lib/nucleo/models/metric_period_row.rb, line 73
def page?
  !self.page.nil?
end
pct_total() click to toggle source

Returns the percent total

@return [Float]

# File lib/nucleo/models/metric_period_row.rb, line 94
def pct_total
  row[translated_key_name(:pct_total)].to_f
end
Also aliased as: percent_total
percent_total()
Alias for: pct_total
period_name() click to toggle source

Returns the period name

@return [String]

# File lib/nucleo/models/metric_period_row.rb, line 41
def period_name
  @attributes['period_name']
end
prior?() click to toggle source

Returns true if this is the prior period

@return [Boolean]

# File lib/nucleo/models/metric_period_row.rb, line 55
def prior?
  'prior' == self.period_name
end
rank() click to toggle source

Returns the rank

@return [Integer]

# File lib/nucleo/models/metric_period_row.rb, line 109
def rank
  row[translated_key_name(:rank)].to_i
end
rank_change() click to toggle source

Returns the rank change

@return [Integer]

# File lib/nucleo/models/metric_period_row.rb, line 102
def rank_change
  row[translated_key_name(:rank_change)].to_i
end
value() click to toggle source

Return the value for this metric

@return [Integer]

# File lib/nucleo/models/metric_period_row.rb, line 80
def value
  row.fetch(self.metric, 0).to_i
end

Private Instance Methods

row() click to toggle source
# File lib/nucleo/models/metric_period_row.rb, line 120
def row
  @attributes.fetch('row', {})
end
translated_key_name(key) click to toggle source
# File lib/nucleo/models/metric_period_row.rb, line 114
def translated_key_name(key)
  key = key.to_s

  [self.metric, key].join('_')
end