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.



14053
14054
14055
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14053

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

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



14051
14052
14053
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14051

def value
  @value
end

Class Method Details

.ALLObject



14073
14074
14075
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14073

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



14058
14059
14060
14061
14062
14063
14064
14065
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14058

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



14068
14069
14070
14071
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14068

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.



14078
14079
14080
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14078

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.



14084
14085
14086
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14084

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

Instance Method Details

#to_hashObject



14088
14089
14090
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14088

def to_hash
  value
end