Class: Io::Flow::V0::Models::DiscountTarget

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ DiscountTarget

Returns a new instance of DiscountTarget.



16901
16902
16903
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16901

def initialize(value)
  @value = HttpClient::Preconditions.assert_class('value', value, String)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



16899
16900
16901
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16899

def value
  @value
end

Class Method Details

.ALLObject



16921
16922
16923
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16921

def DiscountTarget.ALL
  @@all ||= [DiscountTarget.item, DiscountTarget.shipping]
end

.apply(value) ⇒ Object

Returns the instance of DiscountTarget for this value, creating a new instance for an unknown value



16906
16907
16908
16909
16910
16911
16912
16913
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16906

def DiscountTarget.apply(value)
  if value.instance_of?(DiscountTarget)
    value
  else
    HttpClient::Preconditions.assert_class_or_nil('value', value, String)
    value.nil? ? nil : (from_string(value) || DiscountTarget.new(value))
  end
end

.from_string(value) ⇒ Object

Returns the instance of DiscountTarget for this value, or nil if not found



16916
16917
16918
16919
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16916

def DiscountTarget.from_string(value)
  HttpClient::Preconditions.assert_class('value', value, String)
  DiscountTarget.ALL.find { |v| v.value == value }
end

.itemObject

Discount is targeted to an item.



16926
16927
16928
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16926

def DiscountTarget.item
  @@_item ||= DiscountTarget.new('item')
end

.shippingObject

Discount is targeting to shipping. Only applicable if the discount is provided at the order level.



16932
16933
16934
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16932

def DiscountTarget.shipping
  @@_shipping ||= DiscountTarget.new('shipping')
end

Instance Method Details

#to_hashObject



16936
16937
16938
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16936

def to_hash
  value
end