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



12743
12744
12745
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12743

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

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



12741
12742
12743
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12741

def value
  @value
end

Class Method Details

.ALLObject



12763
12764
12765
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12763

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



12748
12749
12750
12751
12752
12753
12754
12755
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12748

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



12758
12759
12760
12761
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12758

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’



12769
12770
12771
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12769

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

Instance Method Details

#to_hashObject



12773
12774
12775
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12773

def to_hash
  value
end