Module: IGMarkets::Format
- Defined in:
- lib/ig_markets/format.rb
Overview
This module contains shared methods for formatting different content types for display.
Class Method Summary collapse
-
.currency(amount, symbol) ⇒ String
Returns a formatted string for the specified currency amount and currency symbol.
-
.seconds(value) ⇒ String
Returns a formatted string for the specified number of seconds in the format ‘[<hours>:]<minutes>:<seconds>`.
Class Method Details
.currency(amount, symbol) ⇒ String
Returns a formatted string for the specified currency amount and currency symbol. Two decimal places are used for all currencies except the Japanese Yen.
13 14 15 16 17 18 19 |
# File 'lib/ig_markets/format.rb', line 13 def currency(amount, symbol) if ['JPY', '¥'].include? symbol "#{symbol} #{format '%i', amount.to_i}" else "#{symbol} #{format '%.2f', amount.to_f}" end end |
.seconds(value) ⇒ String
Returns a formatted string for the specified number of seconds in the format ‘[<hours>:]<minutes>:<seconds>`.
26 27 28 29 30 31 32 33 34 |
# File 'lib/ig_markets/format.rb', line 26 def seconds(value) result = if value >= 60 * 60 "#{value / 60 / 60}:#{Kernel.format('%02i', (value / 60) % 60)}" else (value / 60).to_s end result + ':' + Kernel.format('%02i', value % 60) end |