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.



27987
27988
27989
27990
27991
27992
27993
27994
27995
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 27987

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)))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



27985
27986
27987
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 27985

def amount
  @amount
end

#baseObject (readonly)

Returns the value of attribute base.



27985
27986
27987
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 27985

def base
  @base
end

#currencyObject (readonly)

Returns the value of attribute currency.



27985
27986
27987
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 27985

def currency
  @currency
end

#labelObject (readonly)

Returns the value of attribute label.



27985
27986
27987
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 27985

def label
  @label
end

#requestedObject (readonly)

Returns the value of attribute requested.



27985
27986
27987
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 27985

def requested
  @requested
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



28001
28002
28003
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28001

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

#to_hashObject



28005
28006
28007
28008
28009
28010
28011
28012
28013
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28005

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

#to_jsonObject



27997
27998
27999
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 27997

def to_json
  JSON.dump(to_hash)
end