Class: Io::Flow::V0::Models::LocalizedLineItemDiscount

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

Overview

Represents the requested, base, and localized amounts for a discount on a given line item. It applies to the entire line regardless of quantity.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ LocalizedLineItemDiscount

Returns a new instance of LocalizedLineItemDiscount.



45776
45777
45778
45779
45780
45781
45782
45783
45784
45785
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45776

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:amount, :currency], 'LocalizedLineItemDiscount')
  @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @label = (x = opts.delete(:label); x.nil? ? nil : HttpClient::Preconditions.assert_class('label', x, String))
  @base = (x = opts.delete(:base); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x)))
  @requested = (x = opts.delete(:requested); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x)))
  @discount_label = (x = opts.delete(:discount_label); x.nil? ? nil : HttpClient::Preconditions.assert_class('discount_label', x, String))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



45774
45775
45776
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45774

def amount
  @amount
end

#baseObject (readonly)

Returns the value of attribute base.



45774
45775
45776
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45774

def base
  @base
end

#currencyObject (readonly)

Returns the value of attribute currency.



45774
45775
45776
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45774

def currency
  @currency
end

#discount_labelObject (readonly)

Returns the value of attribute discount_label.



45774
45775
45776
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45774

def discount_label
  @discount_label
end

#labelObject (readonly)

Returns the value of attribute label.



45774
45775
45776
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45774

def label
  @label
end

#requestedObject (readonly)

Returns the value of attribute requested.



45774
45775
45776
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45774

def requested
  @requested
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



45791
45792
45793
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45791

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

#to_hashObject



45795
45796
45797
45798
45799
45800
45801
45802
45803
45804
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45795

def to_hash
  {
    :amount => amount,
    :currency => currency,
    :label => label,
    :base => base.nil? ? nil : base.to_hash,
    :requested => requested.nil? ? nil : requested.to_hash,
    :discount_label => discount_label
  }
end

#to_jsonObject



45787
45788
45789
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 45787

def to_json
  JSON.dump(to_hash)
end