Class: Peddler::Money

Inherits:
Data
  • Object
show all
Defined in:
lib/peddler/money.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount

Returns:

  • (Object)

    the current value of amount



4
5
6
# File 'lib/peddler/money.rb', line 4

def amount
  @amount
end

#currency_codeObject (readonly)

Returns the value of attribute currency_code

Returns:

  • (Object)

    the current value of 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_dObject

steep:ignore



20
21
22
# File 'lib/peddler/money.rb', line 20

def to_d # steep:ignore
  BigDecimal(amount) # steep:ignore
end