Class: Io::Flow::V0::Models::Discount

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

Instance Attribute Summary collapse

Attributes inherited from Promotion

#discriminator

Instance Method Summary collapse

Methods inherited from Promotion

from_json, #to_hash

Constructor Details

#initialize(incoming = {}) ⇒ Discount

Returns a new instance of Discount.



30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30533

def initialize(incoming={})
  super(:discriminator => Promotion::Types::DISCOUNT)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :label, :price], 'Discount')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @code = (x = opts.delete(:code); x.nil? ? nil : HttpClient::Preconditions.assert_class('code', x, String))
  @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
  @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x))
  @attributes = (x = opts.delete(:attributes); x.nil? ? nil : HttpClient::Preconditions.assert_class('attributes', x, Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h })
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



30531
30532
30533
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30531

def attributes
  @attributes
end

#codeObject (readonly)

Returns the value of attribute code.



30531
30532
30533
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30531

def code
  @code
end

#idObject (readonly)

Returns the value of attribute id.



30531
30532
30533
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30531

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



30531
30532
30533
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30531

def label
  @label
end

#priceObject (readonly)

Returns the value of attribute price.



30531
30532
30533
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30531

def price
  @price
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



30548
30549
30550
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30548

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

#subtype_to_hashObject



30552
30553
30554
30555
30556
30557
30558
30559
30560
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30552

def subtype_to_hash
  {
    :id => id,
    :code => code,
    :label => label,
    :price => price.to_hash,
    :attributes => attributes.nil? ? nil : attributes
  }
end

#to_jsonObject



30544
30545
30546
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30544

def to_json
  JSON.dump(to_hash)
end