Class: Io::Flow::Reference::V0::Models::Currency
- Inherits:
-
Object
- Object
- Io::Flow::Reference::V0::Models::Currency
- Defined in:
- lib/io_flow_reference_v0.rb,
lib/flow_reference_v0_client.rb,
lib/flow-reference.rb
Overview
ISO 4217 3-character currency code. See api.flow.io/reference/currencies
Instance Attribute Summary collapse
-
#default_locale ⇒ Object
readonly
Returns the value of attribute default_locale.
-
#iso_4217_3 ⇒ Object
readonly
Returns the value of attribute iso_4217_3.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number_decimals ⇒ Object
readonly
Returns the value of attribute number_decimals.
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
Instance Method Summary collapse
- #copy(incoming = {}) ⇒ Object
-
#initialize(incoming = {}) ⇒ Currency
constructor
A new instance of Currency.
- #to_cents(amount_in) ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(incoming = {}) ⇒ Currency
321 322 323 324 325 326 327 328 329 |
# File 'lib/io_flow_reference_v0.rb', line 321 def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :iso_4217_3, :number_decimals], 'Currency') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @iso_4217_3 = HttpClient::Preconditions.assert_class('iso_4217_3', opts.delete(:iso_4217_3), String) @number_decimals = HttpClient::Preconditions.assert_class('number_decimals', opts.delete(:number_decimals), Integer) @symbols = (x = opts.delete(:symbols); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::Reference::V0::Models::CurrencySymbols) ? x : ::Io::Flow::Reference::V0::Models::CurrencySymbols.new(x))) @default_locale = (x = opts.delete(:default_locale); x.nil? ? nil : HttpClient::Preconditions.assert_class('default_locale', x, String)) end |
Instance Attribute Details
#default_locale ⇒ Object (readonly)
Returns the value of attribute default_locale.
319 320 321 |
# File 'lib/io_flow_reference_v0.rb', line 319 def default_locale @default_locale end |
#iso_4217_3 ⇒ Object (readonly)
Returns the value of attribute iso_4217_3.
319 320 321 |
# File 'lib/io_flow_reference_v0.rb', line 319 def iso_4217_3 @iso_4217_3 end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
319 320 321 |
# File 'lib/io_flow_reference_v0.rb', line 319 def name @name end |
#number_decimals ⇒ Object (readonly)
Returns the value of attribute number_decimals.
319 320 321 |
# File 'lib/io_flow_reference_v0.rb', line 319 def number_decimals @number_decimals end |
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
319 320 321 |
# File 'lib/io_flow_reference_v0.rb', line 319 def symbols @symbols end |
Instance Method Details
#copy(incoming = {}) ⇒ Object
335 336 337 |
# File 'lib/io_flow_reference_v0.rb', line 335 def copy(incoming={}) Currency.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end |
#to_cents(amount_in) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/flow-reference.rb', line 104 def to_cents(amount_in) amount = amount_in.to_f if number_decimals > 0 (amount * (10**number_decimals)).round(0) else amount.to_i end end |
#to_hash ⇒ Object
339 340 341 342 343 344 345 346 347 |
# File 'lib/io_flow_reference_v0.rb', line 339 def to_hash { :name => name, :iso_4217_3 => iso_4217_3, :number_decimals => number_decimals, :symbols => symbols.nil? ? nil : symbols.to_hash, :default_locale => default_locale } end |
#to_json ⇒ Object
331 332 333 |
# File 'lib/io_flow_reference_v0.rb', line 331 def to_json JSON.dump(to_hash) end |