Class: LoyaltyApIs::OfferInfo

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/loyalty_ap_is/models/offer_info.rb

Overview

OfferInfo 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_value:, loyalty_offer_id:, reason:, loyalty_offer_amount: SKIP, loyalty_offer_code: SKIP, loyalty_offer_description: SKIP, loyalty_offer_type: SKIP, loyalty_scheme_code: SKIP, additional_properties: nil) ⇒ OfferInfo

Returns a new instance of OfferInfo.



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

def initialize(discount_value:, loyalty_offer_id:, reason:,
               loyalty_offer_amount: SKIP, loyalty_offer_code: SKIP,
               loyalty_offer_description: SKIP, loyalty_offer_type: SKIP,
               loyalty_scheme_code: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @discount_value = discount_value
  @loyalty_offer_amount = loyalty_offer_amount unless loyalty_offer_amount == SKIP
  @loyalty_offer_code = loyalty_offer_code unless loyalty_offer_code == SKIP
  unless loyalty_offer_description == SKIP
    @loyalty_offer_description =
      loyalty_offer_description
  end
  @loyalty_offer_id = loyalty_offer_id
  @loyalty_offer_type = loyalty_offer_type unless loyalty_offer_type == SKIP
  @loyalty_scheme_code = loyalty_scheme_code unless loyalty_scheme_code == SKIP
  @reason = reason
  @additional_properties = additional_properties
end

Instance Attribute Details

#discount_valueFloat

Discount value of the offer

Returns:

  • (Float)


14
15
16
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 14

def discount_value
  @discount_value
end

#loyalty_offer_amountInteger

Total amount of points awarded for the given product code.

Returns:

  • (Integer)


18
19
20
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 18

def loyalty_offer_amount
  @loyalty_offer_amount
end

#loyalty_offer_codeString

Unique ID of the voucher/coupon.

Returns:

  • (String)


22
23
24
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 22

def loyalty_offer_code
  @loyalty_offer_code
end

#loyalty_offer_descriptionString

Name of loyalty offer

Returns:

  • (String)


26
27
28
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 26

def loyalty_offer_description
  @loyalty_offer_description
end

#loyalty_offer_idString

Loyalty Offer ID

Returns:

  • (String)


30
31
32
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 30

def loyalty_offer_id
  @loyalty_offer_id
end

#loyalty_offer_typeString

Loyalty offer type

Returns:

  • (String)


34
35
36
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 34

def loyalty_offer_type
  @loyalty_offer_type
end

#loyalty_scheme_codeString

Loyalty Scheme code

Returns:

  • (String)


38
39
40
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 38

def loyalty_scheme_code
  @loyalty_scheme_code
end

#reasonString

Offer/reward name

Returns:

  • (String)


42
43
44
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 42

def reason
  @reason
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



96
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
124
125
126
127
128
129
130
131
132
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 96

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  discount_value = hash.key?('discountValue') ? hash['discountValue'] : nil
  loyalty_offer_id =
    hash.key?('loyaltyOfferID') ? hash['loyaltyOfferID'] : nil
  reason = hash.key?('reason') ? hash['reason'] : nil
  loyalty_offer_amount =
    hash.key?('loyaltyOfferAmount') ? hash['loyaltyOfferAmount'] : SKIP
  loyalty_offer_code =
    hash.key?('loyaltyOfferCode') ? hash['loyaltyOfferCode'] : SKIP
  loyalty_offer_description =
    hash.key?('loyaltyOfferDescription') ? hash['loyaltyOfferDescription'] : SKIP
  loyalty_offer_type =
    hash.key?('loyaltyOfferType') ? hash['loyaltyOfferType'] : SKIP
  loyalty_scheme_code =
    hash.key?('loyaltySchemeCode') ? hash['loyaltySchemeCode'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  OfferInfo.new(discount_value: discount_value,
                loyalty_offer_id: loyalty_offer_id,
                reason: reason,
                loyalty_offer_amount: loyalty_offer_amount,
                loyalty_offer_code: loyalty_offer_code,
                loyalty_offer_description: loyalty_offer_description,
                loyalty_offer_type: loyalty_offer_type,
                loyalty_scheme_code: loyalty_scheme_code,
                additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 45

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['discount_value'] = 'discountValue'
  @_hash['loyalty_offer_amount'] = 'loyaltyOfferAmount'
  @_hash['loyalty_offer_code'] = 'loyaltyOfferCode'
  @_hash['loyalty_offer_description'] = 'loyaltyOfferDescription'
  @_hash['loyalty_offer_id'] = 'loyaltyOfferID'
  @_hash['loyalty_offer_type'] = 'loyaltyOfferType'
  @_hash['loyalty_scheme_code'] = 'loyaltySchemeCode'
  @_hash['reason'] = 'reason'
  @_hash
end

.nullablesObject

An array for nullable fields



70
71
72
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 70

def self.nullables
  []
end

.optionalsObject

An array for optional fields



59
60
61
62
63
64
65
66
67
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 59

def self.optionals
  %w[
    loyalty_offer_amount
    loyalty_offer_code
    loyalty_offer_description
    loyalty_offer_type
    loyalty_scheme_code
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



146
147
148
149
150
151
152
153
154
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 146

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_value: #{@discount_value.inspect}, loyalty_offer_amount:"\
  " #{@loyalty_offer_amount.inspect}, loyalty_offer_code: #{@loyalty_offer_code.inspect},"\
  " loyalty_offer_description: #{@loyalty_offer_description.inspect}, loyalty_offer_id:"\
  " #{@loyalty_offer_id.inspect}, loyalty_offer_type: #{@loyalty_offer_type.inspect},"\
  " loyalty_scheme_code: #{@loyalty_scheme_code.inspect}, reason: #{@reason.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



135
136
137
138
139
140
141
142
143
# File 'lib/loyalty_ap_is/models/offer_info.rb', line 135

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_value: #{@discount_value}, loyalty_offer_amount:"\
  " #{@loyalty_offer_amount}, loyalty_offer_code: #{@loyalty_offer_code},"\
  " loyalty_offer_description: #{@loyalty_offer_description}, loyalty_offer_id:"\
  " #{@loyalty_offer_id}, loyalty_offer_type: #{@loyalty_offer_type}, loyalty_scheme_code:"\
  " #{@loyalty_scheme_code}, reason: #{@reason}, additional_properties:"\
  " #{@additional_properties}>"
end