Class: NewStoreApi::Item211

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

Overview

A combination of item id (Sales Order Item UUID) and action to be taken to this item (reroute/cancel or swap).

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(item_id = nil, swap_to = nil) ⇒ Item211

Returns a new instance of Item211.



44
45
46
47
48
# File 'lib/new_store_api/models/item211.rb', line 44

def initialize(item_id = nil, swap_to = nil)
  @action = 'swap'
  @item_id = item_id
  @swap_to = swap_to
end

Instance Attribute Details

#actionString (readonly)

Action to be performed with the item(swap).

Returns:

  • (String)


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

def action
  @action
end

#item_idString

Identifier (Sales Order Item UUID) of a single item in logistic order.

Returns:

  • (String)


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

def item_id
  @item_id
end

#swap_toSwapTo

Properties of the new item.

Returns:



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

def swap_to
  @swap_to
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/new_store_api/models/item211.rb', line 51

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  item_id = hash.key?('item_id') ? hash['item_id'] : nil
  swap_to = SwapTo.from_hash(hash['swap_to']) if hash['swap_to']

  # Create object from extracted values.
  Item211.new(item_id,
              swap_to)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['action'] = 'action'
  @_hash['item_id'] = 'item_id'
  @_hash['swap_to'] = 'swap_to'
  @_hash
end

.nullablesObject

An array for nullable fields



40
41
42
# File 'lib/new_store_api/models/item211.rb', line 40

def self.nullables
  []
end

.optionalsObject

An array for optional fields



35
36
37
# File 'lib/new_store_api/models/item211.rb', line 35

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Item211 | Hash)

    value against the validation is performed.



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
# File 'lib/new_store_api/models/item211.rb', line 65

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.action,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.item_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.swap_to,
                              ->(val) { SwapTo.validate(val) },
                              is_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['action'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['item_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['swap_to'],
                            ->(val) { SwapTo.validate(val) },
                            is_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



98
99
100
101
102
# File 'lib/new_store_api/models/item211.rb', line 98

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

#to_sObject

Provides a human-readable string representation of the object.



92
93
94
95
# File 'lib/new_store_api/models/item211.rb', line 92

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} action: #{@action}, item_id: #{@item_id}, swap_to: #{@swap_to}>"
end