Module: Squid::Format

Includes:
ActiveSupport::NumberHelper
Included in:
Axis, Point
Defined in:
lib/squid/format.rb

Instance Method Summary collapse

Instance Method Details

#format_for(value, format) ⇒ Object


8
9
10
11
12
13
14
15
16
# File 'lib/squid/format.rb', line 8

def format_for(value, format)
  case format
    when :percentage then number_to_percentage value, precision: 1
    when :currency then number_to_currency value
    when :seconds then number_to_minutes_and_seconds value
    when :float then number_to_delimited value
    else number_to_delimited value.to_i
  end.to_s
end

#number_to_minutes_and_seconds(value) ⇒ Object


18
19
20
# File 'lib/squid/format.rb', line 18

def number_to_minutes_and_seconds(value)
  "#{value.round / 60}:#{(value.round % 60).to_s.rjust 2, '0'}"
end