Class: NewStoreApi::CartDiscount
- Defined in:
- lib/new_store_api/models/cart_discount.rb
Overview
List of discounts
Instance Attribute Summary collapse
-
#cart_id ⇒ String
Cart id.
-
#currency ⇒ String
The currency of the cart.
-
#items ⇒ Array[ItemDiscount]
The individual items that the cart contains.
-
#warnings ⇒ Array[Warning]
The individual items that the cart contains.
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(cart_id = nil, currency = nil, items = SKIP, warnings = SKIP) ⇒ CartDiscount
constructor
A new instance of CartDiscount.
-
#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(cart_id = nil, currency = nil, items = SKIP, warnings = SKIP) ⇒ CartDiscount
Returns a new instance of CartDiscount.
51 52 53 54 55 56 |
# File 'lib/new_store_api/models/cart_discount.rb', line 51 def initialize(cart_id = nil, currency = nil, items = SKIP, warnings = SKIP) @cart_id = cart_id @currency = currency @items = items unless items == SKIP @warnings = warnings unless warnings == SKIP end |
Instance Attribute Details
#cart_id ⇒ String
Cart id.
14 15 16 |
# File 'lib/new_store_api/models/cart_discount.rb', line 14 def cart_id @cart_id end |
#currency ⇒ String
The currency of the cart.
18 19 20 |
# File 'lib/new_store_api/models/cart_discount.rb', line 18 def currency @currency end |
#items ⇒ Array[ItemDiscount]
The individual items that the cart contains.
22 23 24 |
# File 'lib/new_store_api/models/cart_discount.rb', line 22 def items @items end |
#warnings ⇒ Array[Warning]
The individual items that the cart contains.
26 27 28 |
# File 'lib/new_store_api/models/cart_discount.rb', line 26 def warnings @warnings end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/new_store_api/models/cart_discount.rb', line 59 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. cart_id = hash.key?('cart_id') ? hash['cart_id'] : nil currency = hash.key?('currency') ? hash['currency'] : nil # Parameter is an array, so we need to iterate through it items = nil unless hash['items'].nil? items = [] hash['items'].each do |structure| items << (ItemDiscount.from_hash(structure) if structure) end end items = SKIP unless hash.key?('items') # Parameter is an array, so we need to iterate through it warnings = nil unless hash['warnings'].nil? warnings = [] hash['warnings'].each do |structure| warnings << (Warning.from_hash(structure) if structure) end end warnings = SKIP unless hash.key?('warnings') # Create object from extracted values. CartDiscount.new(cart_id, currency, items, warnings) 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/cart_discount.rb', line 29 def self.names @_hash = {} if @_hash.nil? @_hash['cart_id'] = 'cart_id' @_hash['currency'] = 'currency' @_hash['items'] = 'items' @_hash['warnings'] = 'warnings' @_hash end |
.nullables ⇒ Object
An array for nullable fields
47 48 49 |
# File 'lib/new_store_api/models/cart_discount.rb', line 47 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
39 40 41 42 43 44 |
# File 'lib/new_store_api/models/cart_discount.rb', line 39 def self.optionals %w[ items warnings ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
101 102 103 104 105 |
# File 'lib/new_store_api/models/cart_discount.rb', line 101 def inspect class_name = self.class.name.split('::').last "<#{class_name} cart_id: #{@cart_id.inspect}, currency: #{@currency.inspect}, items:"\ " #{@items.inspect}, warnings: #{@warnings.inspect}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
94 95 96 97 98 |
# File 'lib/new_store_api/models/cart_discount.rb', line 94 def to_s class_name = self.class.name.split('::').last "<#{class_name} cart_id: #{@cart_id}, currency: #{@currency}, items: #{@items}, warnings:"\ " #{@warnings}>" end |