Class: Stats::StatsEntry

Inherits:
Object
  • Object
show all
Defined in:
app/services/stats.rb

Instance Method Summary collapse

Constructor Details

#initialize(date, entry, prev_entry = nil) ⇒ StatsEntry

Returns a new instance of StatsEntry.


45
46
47
48
49
50
# File 'app/services/stats.rb', line 45

def initialize(date, entry, prev_entry = nil)
  @date = date
  @entry = entry
  @prev_entry = prev_entry || {}
  fix_missing_keys
end

Instance Method Details

#shown_dateObject


65
66
67
# File 'app/services/stats.rb', line 65

def shown_date
  @date - 1
end

#val(key, add_change = true) ⇒ Object


56
57
58
59
60
61
62
63
# File 'app/services/stats.rb', line 56

def val(key, add_change = true)
  v = value(key, add_change)
  str = v.to_s
  if add_change
    str << " (#{v.change_prefix}#{v.change})"
  end
  str
end

#value(key, add_change = true) ⇒ Object


52
53
54
# File 'app/services/stats.rb', line 52

def value(key, add_change = true)
  value = StatsValue.new(key, @entry[key].to_i, @prev_entry[key].to_i)
end