Class: Io::Flow::V0::Models::OrderPriceDetail

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ OrderPriceDetail

Returns a new instance of OrderPriceDetail.



13573
13574
13575
13576
13577
13578
13579
13580
13581
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13573

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:key, :currency, :amount, :label, :components], 'OrderPriceDetail')
  @key = (x = opts.delete(:key); x.is_a?(::Io::Flow::V0::Models::OrderPriceDetailKey) ? x : ::Io::Flow::V0::Models::OrderPriceDetailKey.apply(x))
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
  @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
  @components = HttpClient::Preconditions.assert_class('components', opts.delete(:components), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::OrderPriceDetailComponent) ? x : ::Io::Flow::V0::Models::OrderPriceDetailComponent.new(x)) }
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



13571
13572
13573
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13571

def amount
  @amount
end

#componentsObject (readonly)

Returns the value of attribute components.



13571
13572
13573
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13571

def components
  @components
end

#currencyObject (readonly)

Returns the value of attribute currency.



13571
13572
13573
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13571

def currency
  @currency
end

#keyObject (readonly)

Returns the value of attribute key.



13571
13572
13573
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13571

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



13571
13572
13573
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13571

def label
  @label
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



13587
13588
13589
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13587

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

#to_hashObject



13591
13592
13593
13594
13595
13596
13597
13598
13599
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13591

def to_hash
  {
    :key => key.value,
    :currency => currency,
    :amount => amount,
    :label => label,
    :components => components.map { |o| o.to_hash }
  }
end

#to_jsonObject



13583
13584
13585
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13583

def to_json
  JSON.dump(to_hash)
end