Class: Peddler::Money

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.[](amount:, currency_code:) ⇒ Money .[](arg0, arg1) ⇒ Money



6
7
# File 'sig/peddler/money.rbs', line 6

def self.[]: (amount: String, currency_code: String) -> Money
| (String, String) -> Money

.members ⇒ [ :amount, :currency_code ]



9
# File 'sig/peddler/money.rbs', line 9

def self.members: () -> [ :amount, :currency_code ]

.new(amount:, currency_code:) ⇒ Money .new(arg0, arg1) ⇒ Money



3
4
# File 'sig/peddler/money.rbs', line 3

def self.new: (amount: String, currency_code: String) -> Money
| (String, String) -> Money

.parse(value) ⇒ Money?



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

#members ⇒ [ :amount, :currency_code ]



16
# File 'sig/peddler/money.rbs', line 16

def members: () -> [ :amount, :currency_code ]

#to_d ⇒ BigDecimal

steep:ignore



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

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

#to_h ⇒ { amount: String, currency_code: String }



18
# File 'sig/peddler/money.rbs', line 18

def to_h: () -> { amount: String, currency_code: String }