Class: Mint::Utils
- Inherits:
-
Object
- Object
- Mint::Utils
- Defined in:
- lib/mint/money/utils.rb
Overview
Special utilities
Class Method Summary collapse
-
.to_amount(value, currency) ⇒ BigDecimal
Normalize and guess amount’s type.
-
.to_format(value, currency) ⇒ String
Format number as string with correct precision.
-
.to_key(key) ⇒ Symbol
Normalize string to our keys format.
Class Method Details
.to_amount(value, currency) ⇒ BigDecimal
Normalize and guess amount’s type
26 27 28 |
# File 'lib/mint/money/utils.rb', line 26 def to_amount(value, currency) to_bigdecimal(value).round(precision(currency)) end |
.to_format(value, currency) ⇒ String
Format number as string with correct precision
34 35 36 |
# File 'lib/mint/money/utils.rb', line 34 def to_format(value, currency) format("%.#{precision(currency)}f", value.to_f) end |
.to_key(key) ⇒ Symbol
Normalize string to our keys format
16 17 18 |
# File 'lib/mint/money/utils.rb', line 16 def to_key(key) key.to_s.upcase.to_sym end |