Class: NewStoreApi::Discount

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

Overview

A discount detail.

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(change = nil, coupon_code = nil, description = nil, discount = nil, discount_source = nil, id = nil, kind = nil, name = nil, promotion_type = nil) ⇒ Discount

Returns a new instance of Discount.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/new_store_api/models/discount.rb', line 76

def initialize(change = nil, coupon_code = nil, description = nil,
               discount = nil, discount_source = nil, id = nil, kind = nil,
               name = nil, promotion_type = nil)
  @change = change
  @coupon_code = coupon_code
  @description = description
  @discount = discount
  @discount_source = discount_source
  @id = id
  @kind = kind
  @name = name
  @promotion_type = promotion_type
end

Instance Attribute Details

#changeString

The change in price resulting from this discount, with a number of decimals based on currency

Returns:

  • (String)


15
16
17
# File 'lib/new_store_api/models/discount.rb', line 15

def change
  @change
end

#coupon_codeString

The coupon, if any, associated with this discount

Returns:

  • (String)


19
20
21
# File 'lib/new_store_api/models/discount.rb', line 19

def coupon_code
  @coupon_code
end

#descriptionString

The discount's description

Returns:

  • (String)


23
24
25
# File 'lib/new_store_api/models/discount.rb', line 23

def description
  @description
end

#discountString

The value of the discount, with a number of decimals based on currency

Returns:

  • (String)


27
28
29
# File 'lib/new_store_api/models/discount.rb', line 27

def discount
  @discount
end

#discount_sourceString

The source of the discount. For example, Promotion implies that the discount is based on automatic promotions, while Coupon refers to discounts from coupons.

Returns:

  • (String)


33
34
35
# File 'lib/new_store_api/models/discount.rb', line 33

def discount_source
  @discount_source
end

#idString

The discount's id

Returns:

  • (String)


37
38
39
# File 'lib/new_store_api/models/discount.rb', line 37

def id
  @id
end

#kindString

The discount's kind

Returns:

  • (String)


41
42
43
# File 'lib/new_store_api/models/discount.rb', line 41

def kind
  @kind
end

#nameString

The discount's name

Returns:

  • (String)


45
46
47
# File 'lib/new_store_api/models/discount.rb', line 45

def name
  @name
end

#promotion_typeString

The discount's promotion type e.g. cart level or product level

Returns:

  • (String)


49
50
51
# File 'lib/new_store_api/models/discount.rb', line 49

def promotion_type
  @promotion_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/new_store_api/models/discount.rb', line 91

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  change = hash.key?('change') ? hash['change'] : nil
  coupon_code = hash.key?('coupon_code') ? hash['coupon_code'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  discount = hash.key?('discount') ? hash['discount'] : nil
  discount_source =
    hash.key?('discount_source') ? hash['discount_source'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  kind = hash.key?('kind') ? hash['kind'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  promotion_type =
    hash.key?('promotion_type') ? hash['promotion_type'] : nil

  # Create object from extracted values.
  Discount.new(change,
               coupon_code,
               description,
               discount,
               discount_source,
               id,
               kind,
               name,
               promotion_type)
end

.namesObject

A mapping from model property names to API property names.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/new_store_api/models/discount.rb', line 52

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['change'] = 'change'
  @_hash['coupon_code'] = 'coupon_code'
  @_hash['description'] = 'description'
  @_hash['discount'] = 'discount'
  @_hash['discount_source'] = 'discount_source'
  @_hash['id'] = 'id'
  @_hash['kind'] = 'kind'
  @_hash['name'] = 'name'
  @_hash['promotion_type'] = 'promotion_type'
  @_hash
end

.nullablesObject

An array for nullable fields



72
73
74
# File 'lib/new_store_api/models/discount.rb', line 72

def self.nullables
  []
end

.optionalsObject

An array for optional fields



67
68
69
# File 'lib/new_store_api/models/discount.rb', line 67

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



128
129
130
131
132
133
134
# File 'lib/new_store_api/models/discount.rb', line 128

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} change: #{@change.inspect}, coupon_code: #{@coupon_code.inspect},"\
  " description: #{@description.inspect}, discount: #{@discount.inspect}, discount_source:"\
  " #{@discount_source.inspect}, id: #{@id.inspect}, kind: #{@kind.inspect}, name:"\
  " #{@name.inspect}, promotion_type: #{@promotion_type.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



120
121
122
123
124
125
# File 'lib/new_store_api/models/discount.rb', line 120

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} change: #{@change}, coupon_code: #{@coupon_code}, description:"\
  " #{@description}, discount: #{@discount}, discount_source: #{@discount_source}, id: #{@id},"\
  " kind: #{@kind}, name: #{@name}, promotion_type: #{@promotion_type}>"
end