Class: Io::Flow::V0::Models::DiscountForm

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ DiscountForm

Returns a new instance of DiscountForm.



35028
35029
35030
35031
35032
35033
35034
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 35028

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:offer], 'DiscountForm')
  @offer = (x = opts.delete(:offer); x.is_a?(::Io::Flow::V0::Models::DiscountOffer) ? x : ::Io::Flow::V0::Models::DiscountOffer.from_json(x))
  @target = (x = (x = opts.delete(:target); x.nil? ? "item" : x); x.is_a?(::Io::Flow::V0::Models::DiscountTarget) ? x : ::Io::Flow::V0::Models::DiscountTarget.apply(x))
  @label = (x = opts.delete(:label); x.nil? ? nil : HttpClient::Preconditions.assert_class('label', x, String))
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



35026
35027
35028
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 35026

def label
  @label
end

#offerObject (readonly)

Returns the value of attribute offer.



35026
35027
35028
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 35026

def offer
  @offer
end

#targetObject (readonly)

Returns the value of attribute target.



35026
35027
35028
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 35026

def target
  @target
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



35040
35041
35042
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 35040

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

#to_hashObject



35044
35045
35046
35047
35048
35049
35050
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 35044

def to_hash
  {
    :offer => offer.to_hash,
    :target => target.value,
    :label => label
  }
end

#to_jsonObject



35036
35037
35038
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 35036

def to_json
  JSON.dump(to_hash)
end