Class: NewStoreApi::ItemDiscount
- Defined in:
- lib/new_store_api/models/item_discount.rb
Overview
An individual item in the cart.
Instance Attribute Summary collapse
-
#adjusted_price ⇒ String
Item price after applying discounts.
-
#discount_forbidden ⇒ TrueClass | FalseClass
Indicate whether discount is forbidden or not for this item.
-
#discounts ⇒ Array[Discount]
An array of discounts details.
-
#id ⇒ String
The ID of the item in the cart.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(adjusted_price = nil, discount_forbidden = false, discounts = nil, id = nil) ⇒ ItemDiscount
constructor
A new instance of ItemDiscount.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(adjusted_price = nil, discount_forbidden = false, discounts = nil, id = nil) ⇒ ItemDiscount
Returns a new instance of ItemDiscount.
48 49 50 51 52 53 54 |
# File 'lib/new_store_api/models/item_discount.rb', line 48 def initialize(adjusted_price = nil, discount_forbidden = false, discounts = nil, id = nil) @adjusted_price = adjusted_price @discount_forbidden = discount_forbidden @discounts = discounts @id = id end |
Instance Attribute Details
#adjusted_price ⇒ String
Item price after applying discounts.
14 15 16 |
# File 'lib/new_store_api/models/item_discount.rb', line 14 def adjusted_price @adjusted_price end |
#discount_forbidden ⇒ TrueClass | FalseClass
Indicate whether discount is forbidden or not for this item.
18 19 20 |
# File 'lib/new_store_api/models/item_discount.rb', line 18 def discount_forbidden @discount_forbidden end |
#discounts ⇒ Array[Discount]
An array of discounts details.
22 23 24 |
# File 'lib/new_store_api/models/item_discount.rb', line 22 def discounts @discounts end |
#id ⇒ String
The ID of the item in the cart.
26 27 28 |
# File 'lib/new_store_api/models/item_discount.rb', line 26 def id @id end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/new_store_api/models/item_discount.rb', line 57 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. adjusted_price = hash.key?('adjusted_price') ? hash['adjusted_price'] : nil discount_forbidden = hash['discount_forbidden'] ||= false # Parameter is an array, so we need to iterate through it discounts = nil unless hash['discounts'].nil? discounts = [] hash['discounts'].each do |structure| discounts << (Discount.from_hash(structure) if structure) end end discounts = nil unless hash.key?('discounts') id = hash.key?('id') ? hash['id'] : nil # Create object from extracted values. ItemDiscount.new(adjusted_price, discount_forbidden, discounts, id) end |
.names ⇒ Object
A mapping from model property names to API property names.
29 30 31 32 33 34 35 36 |
# File 'lib/new_store_api/models/item_discount.rb', line 29 def self.names @_hash = {} if @_hash.nil? @_hash['adjusted_price'] = 'adjusted_price' @_hash['discount_forbidden'] = 'discount_forbidden' @_hash['discounts'] = 'discounts' @_hash['id'] = 'id' @_hash end |
.nullables ⇒ Object
An array for nullable fields
44 45 46 |
# File 'lib/new_store_api/models/item_discount.rb', line 44 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
39 40 41 |
# File 'lib/new_store_api/models/item_discount.rb', line 39 def self.optionals [] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
91 92 93 94 95 |
# File 'lib/new_store_api/models/item_discount.rb', line 91 def inspect class_name = self.class.name.split('::').last "<#{class_name} adjusted_price: #{@adjusted_price.inspect}, discount_forbidden:"\ " #{@discount_forbidden.inspect}, discounts: #{@discounts.inspect}, id: #{@id.inspect}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
84 85 86 87 88 |
# File 'lib/new_store_api/models/item_discount.rb', line 84 def to_s class_name = self.class.name.split('::').last "<#{class_name} adjusted_price: #{@adjusted_price}, discount_forbidden:"\ " #{@discount_forbidden}, discounts: #{@discounts}, id: #{@id}>" end |