Class: Io::Flow::V0::Models::PriceDetail

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

Overview

Represents a top-level price detail, e.g. ‘Subtotal’ or ‘VAT’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ PriceDetail

Returns a new instance of PriceDetail.



43216
43217
43218
43219
43220
43221
43222
43223
43224
43225
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43216

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:key, :components, :amount, :label], 'PriceDetail')
  @key = (x = opts.delete(:key); x.is_a?(::Io::Flow::V0::Models::PriceDetailKey) ? x : ::Io::Flow::V0::Models::PriceDetailKey.apply(x))
  @components = HttpClient::Preconditions.assert_class('components', opts.delete(:components), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::PriceDetailComponent) ? x : ::Io::Flow::V0::Models::PriceDetailComponent.new(x)) }
  @amount = HttpClient::Preconditions.assert_class('amount', HttpClient::Helper.to_big_decimal(opts.delete(:amount)), BigDecimal)
  @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
  @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String))
  @basis = (x = opts.delete(:basis); x.nil? ? nil : HttpClient::Preconditions.assert_class('basis', HttpClient::Helper.to_big_decimal(x), BigDecimal))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



43214
43215
43216
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43214

def amount
  @amount
end

#basisObject (readonly)

Returns the value of attribute basis.



43214
43215
43216
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43214

def basis
  @basis
end

#componentsObject (readonly)

Returns the value of attribute components.



43214
43215
43216
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43214

def components
  @components
end

#keyObject (readonly)

Returns the value of attribute key.



43214
43215
43216
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43214

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



43214
43215
43216
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43214

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



43214
43215
43216
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43214

def name
  @name
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



43231
43232
43233
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43231

def copy(incoming={})
  PriceDetail.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



43235
43236
43237
43238
43239
43240
43241
43242
43243
43244
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43235

def to_hash
  {
    :key => key.value,
    :components => components.map { |o| o.to_hash },
    :amount => amount.to_f.to_s,
    :label => label,
    :name => name,
    :basis => basis.to_f.to_s
  }
end

#to_jsonObject



43227
43228
43229
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 43227

def to_json
  JSON.dump(to_hash)
end