Class: NewStoreApi::InjectedOrderDiscountInfo1

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/injected_order_discount_info1.rb

Overview

InjectedOrderDiscountInfo1 Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(discount_ref = nil, original_value = nil, price_adjustment = nil, coupon_code = SKIP, description = SKIP) ⇒ InjectedOrderDiscountInfo1

Returns a new instance of InjectedOrderDiscountInfo1.



63
64
65
66
67
68
69
70
71
72
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 63

def initialize(discount_ref = nil, original_value = nil,
               price_adjustment = nil, coupon_code = SKIP,
               description = SKIP)
  @coupon_code = coupon_code unless coupon_code == SKIP
  @description = description unless description == SKIP
  @discount_ref = discount_ref
  @original_value = original_value
  @price_adjustment = price_adjustment
  @type = 'percentage'
end

Instance Attribute Details

#coupon_codeString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 14

def coupon_code
  @coupon_code
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


18
19
20
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 18

def description
  @description
end

#discount_refString

A string token identifying the discount, e.g. BLACK_FRIDAY_SALE.

Returns:

  • (String)


22
23
24
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 22

def discount_ref
  @discount_ref
end

#original_valueFloat

Discount applied. In the case of an item_discount_info, the discount is applied to the item itself. In the case of an item_order_discount_info, the discount is applied to the whole order.

Returns:

  • (Float)


28
29
30
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 28

def original_value
  @original_value
end

#price_adjustmentFloat

Monetary discount amount applied to the current item.

Returns:

  • (Float)


32
33
34
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 32

def price_adjustment
  @price_adjustment
end

#typeString (readonly)

Monetary discount amount applied to the current item.

Returns:

  • (String)


36
37
38
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 36

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 75

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  discount_ref = hash.key?('discount_ref') ? hash['discount_ref'] : nil
  original_value =
    hash.key?('original_value') ? hash['original_value'] : nil
  price_adjustment =
    hash.key?('price_adjustment') ? hash['price_adjustment'] : nil
  coupon_code = hash.key?('coupon_code') ? hash['coupon_code'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP

  # Create object from extracted values.
  InjectedOrderDiscountInfo1.new(discount_ref,
                                 original_value,
                                 price_adjustment,
                                 coupon_code,
                                 description)
end

.namesObject

A mapping from model property names to API property names.



39
40
41
42
43
44
45
46
47
48
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 39

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['coupon_code'] = 'coupon_code'
  @_hash['description'] = 'description'
  @_hash['discount_ref'] = 'discount_ref'
  @_hash['original_value'] = 'original_value'
  @_hash['price_adjustment'] = 'price_adjustment'
  @_hash['type'] = 'type'
  @_hash
end

.nullablesObject

An array for nullable fields



59
60
61
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 59

def self.nullables
  []
end

.optionalsObject

An array for optional fields



51
52
53
54
55
56
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 51

def self.optionals
  %w[
    coupon_code
    description
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 97

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.discount_ref,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.original_value,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.price_adjustment,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.type,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['discount_ref'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['original_value'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['price_adjustment'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['type'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



134
135
136
137
138
139
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 134

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} coupon_code: #{@coupon_code.inspect}, description: #{@description.inspect},"\
  " discount_ref: #{@discount_ref.inspect}, original_value: #{@original_value.inspect},"\
  " price_adjustment: #{@price_adjustment.inspect}, type: #{@type.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



126
127
128
129
130
131
# File 'lib/new_store_api/models/injected_order_discount_info1.rb', line 126

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} coupon_code: #{@coupon_code}, description: #{@description}, discount_ref:"\
  " #{@discount_ref}, original_value: #{@original_value}, price_adjustment:"\
  " #{@price_adjustment}, type: #{@type}>"
end