Module: Totals

Included in:
Block, Day, Month
Defined in:
lib/totals.rb

Defined Under Namespace

Modules: Formatter Classes: DecimalFormatter, DigitalFormatter

Constant Summary collapse

FORMATTERS =
{
  :digital => DigitalFormatter,
  :decimal => DecimalFormatter
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.format(seconds) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/totals.rb', line 45

def format(seconds)
  totals_format = Punch.config.totals_format
  formatter_class = FORMATTERS.fetch(totals_format) do
    raise "Unknown totals format #{totals_format}"
  end

  formatter_class.new(seconds).format
end

Instance Method Details

#totalObject


35
36
37
# File 'lib/totals.rb', line 35

def total
  children.inject(0) { |sum, c| sum += c.total }
end

#total_strObject


39
40
41
# File 'lib/totals.rb', line 39

def total_str
  Totals.format total
end