Class: Peddler::Money
- Inherits:
-
Data
- Object
- Data
- Peddler::Money
- Defined in:
- lib/peddler/money.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency_code ⇒ Object
readonly
Returns the value of attribute currency_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#to_d ⇒ Object
steep:ignore.
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount
4 5 6 |
# File 'lib/peddler/money.rb', line 4 def amount @amount end |
#currency_code ⇒ Object (readonly)
Returns the value of attribute currency_code
4 5 6 |
# File 'lib/peddler/money.rb', line 4 def currency_code @currency_code end |
Class Method Details
.parse(value) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/peddler/money.rb', line 6 def parse(value) return unless value currency_code = value["CurrencyCode"] || value["currencyCode"] || value["currency_code"] amount_value = value["Amount"] || value["amount"] || value["CurrencyAmount"] || value["currencyAmount"] || value["currency_amount"] || value["value"] decimal_amount = BigDecimal(amount_value.to_s) # JPY has no subunits amount = currency_code == "JPY" ? decimal_amount.to_i.to_s : format("%.2f", decimal_amount) new(amount:, currency_code:) end |
Instance Method Details
#to_d ⇒ Object
steep:ignore
20 21 22 |
# File 'lib/peddler/money.rb', line 20 def to_d # steep:ignore BigDecimal(amount) # steep:ignore end |