Class: Hola::Utils::Money
- Inherits:
-
Object
- Object
- Hola::Utils::Money
- Defined in:
- lib/hola/utils/money.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ Money
constructor
A new instance of Money.
- #parse ⇒ Object
- #to_currency ⇒ Object
Constructor Details
#initialize(value) ⇒ Money
Returns a new instance of Money.
19 20 21 |
# File 'lib/hola/utils/money.rb', line 19 def initialize(value) @value = value end |
Class Method Details
.parse ⇒ Object
10 11 12 |
# File 'lib/hola/utils/money.rb', line 10 def parse(...) new(...).parse end |
.to_currency ⇒ Object
14 15 16 |
# File 'lib/hola/utils/money.rb', line 14 def to_currency(...) new(...).to_currency end |
Instance Method Details
#parse ⇒ Object
23 24 25 26 27 |
# File 'lib/hola/utils/money.rb', line 23 def parse BigDecimal((value || 0).to_s.strip) rescue ArgumentError, TypeError => err raise Error.new(err.) end |
#to_currency ⇒ Object
29 30 31 |
# File 'lib/hola/utils/money.rb', line 29 def to_currency "#{format("%.2f", value)}#{Product.currency}" end |