Class: NewStoreApi::RoutingSimulationLineItem

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

Overview

Order line item supplied for a routing simulation run.

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(line_item_id = nil, product_id = nil, price = 0) ⇒ RoutingSimulationLineItem

Returns a new instance of RoutingSimulationLineItem.



45
46
47
48
49
# File 'lib/new_store_api/models/routing_simulation_line_item.rb', line 45

def initialize(line_item_id = nil, product_id = nil, price = 0)
  @line_item_id = line_item_id
  @price = price unless price == SKIP
  @product_id = product_id
end

Instance Attribute Details

#line_item_idString

Unique identifier for the line item in the simulated order.

Returns:

  • (String)


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

def line_item_id
  @line_item_id
end

#priceFloat

Unit price used by routing reducers that depend on order amount.

Returns:

  • (Float)


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

def price
  @price
end

#product_idString

Catalog product identifier for the line item.

Returns:

  • (String)


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

def product_id
  @product_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  line_item_id = hash.key?('line_item_id') ? hash['line_item_id'] : nil
  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  price = hash['price'] ||= 0

  # Create object from extracted values.
  RoutingSimulationLineItem.new(line_item_id,
                                product_id,
                                price)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/new_store_api/models/routing_simulation_line_item.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['line_item_id'] = 'line_item_id'
  @_hash['price'] = 'price'
  @_hash['product_id'] = 'product_id'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
37
38
# File 'lib/new_store_api/models/routing_simulation_line_item.rb', line 34

def self.optionals
  %w[
    price
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



74
75
76
77
78
# File 'lib/new_store_api/models/routing_simulation_line_item.rb', line 74

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} line_item_id: #{@line_item_id.inspect}, price: #{@price.inspect},"\
  " product_id: #{@product_id.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



67
68
69
70
71
# File 'lib/new_store_api/models/routing_simulation_line_item.rb', line 67

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} line_item_id: #{@line_item_id}, price: #{@price}, product_id:"\
  " #{@product_id}>"
end