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.



16195
16196
16197
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16195

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

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



16193
16194
16195
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16193

def value
  @value
end

Class Method Details

.ALLObject



16215
16216
16217
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16215

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

.apply(value) ⇒ Object

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



16200
16201
16202
16203
16204
16205
16206
16207
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16200

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



16210
16211
16212
16213
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16210

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’



16221
16222
16223
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16221

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

.symbol_prefixObject

Indicates that a currency symbol should appear as a prefix to the price label. e.g $100



16227
16228
16229
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16227

def CurrencyLabelFormatter.symbol_prefix
  @@_symbol_prefix ||= CurrencyLabelFormatter.new('symbol_prefix')
end

.symbol_suffixObject

Indicates that a currency symbol should appear as a suffix to the price label. e.g 100 $



16233
16234
16235
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16233

def CurrencyLabelFormatter.symbol_suffix
  @@_symbol_suffix ||= CurrencyLabelFormatter.new('symbol_suffix')
end

Instance Method Details

#to_hashObject



16237
16238
16239
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16237

def to_hash
  value
end