Class: Io::Flow::V0::Models::CurrencyLabelFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ CurrencyLabelFormatter

Returns a new instance of CurrencyLabelFormatter.



13461
13462
13463
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13461

def initialize(value)
  @value = HttpClient::Preconditions.assert_class('value', value, String)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



13459
13460
13461
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13459

def value
  @value
end

Class Method Details

.ALLObject



13481
13482
13483
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13481

def CurrencyLabelFormatter.ALL
  @@all ||= [CurrencyLabelFormatter.strip_trailing_zeros]
end

.apply(value) ⇒ Object

Returns the instance of CurrencyLabelFormatter for this value, creating a new instance for an unknown value



13466
13467
13468
13469
13470
13471
13472
13473
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13466

def CurrencyLabelFormatter.apply(value)
  if value.instance_of?(CurrencyLabelFormatter)
    value
  else
    HttpClient::Preconditions.assert_class_or_nil('value', value, String)
    value.nil? ? nil : (from_string(value) || CurrencyLabelFormatter.new(value))
  end
end

.from_string(value) ⇒ Object

Returns the instance of CurrencyLabelFormatter for this value, or nil if not found



13476
13477
13478
13479
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13476

def CurrencyLabelFormatter.from_string(value)
  HttpClient::Preconditions.assert_class('value', value, String)
  CurrencyLabelFormatter.ALL.find { |v| v.value == value }
end

.strip_trailing_zerosObject

If a price ends in ‘.00’ or ‘,00’, we remove the cents and just display the price as a whole number. e.g. ‘A$100.00’ becomes ‘A$100’



13487
13488
13489
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13487

def CurrencyLabelFormatter.strip_trailing_zeros
  @@_strip_trailing_zeros ||= CurrencyLabelFormatter.new('strip_trailing_zeros')
end

Instance Method Details

#to_hashObject



13491
13492
13493
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13491

def to_hash
  value
end