Class: WalmartApIs::Window

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/walmart_ap_is/models/window.rb

Overview

Contains a start and end DateTime representing a time range.

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(mend:, start:, editable_until: SKIP, additional_properties: nil) ⇒ Window

Returns a new instance of Window.



46
47
48
49
50
51
52
53
54
55
# File 'lib/walmart_ap_is/models/window.rb', line 46

def initialize(mend:, start:, editable_until: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @editable_until = editable_until unless editable_until == SKIP
  @mend = mend
  @start = start
  @additional_properties = additional_properties
end

Instance Attribute Details

#editable_untilDateTime

The timestamp at which this window can no longer be edited.

Returns:

  • (DateTime)


15
16
17
# File 'lib/walmart_ap_is/models/window.rb', line 15

def editable_until
  @editable_until
end

#mendDateTime

The end timestamp of the window.

Returns:

  • (DateTime)


19
20
21
# File 'lib/walmart_ap_is/models/window.rb', line 19

def mend
  @mend
end

#startDateTime

The start timestamp of the window.

Returns:

  • (DateTime)


23
24
25
# File 'lib/walmart_ap_is/models/window.rb', line 23

def start
  @start
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



58
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
# File 'lib/walmart_ap_is/models/window.rb', line 58

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  mend = if hash.key?('end')
           (DateTimeHelper.from_rfc3339(hash['end']) if hash['end'])
         end
  start = if hash.key?('start')
            (DateTimeHelper.from_rfc3339(hash['start']) if hash['start'])
          end
  editable_until = if hash.key?('editableUntil')
                     (DateTimeHelper.from_rfc3339(hash['editableUntil']) if hash['editableUntil'])
                   else
                     SKIP
                   end

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Window.new(mend: mend,
             start: start,
             editable_until: editable_until,
             additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['editable_until'] = 'editableUntil'
  @_hash['mend'] = 'end'
  @_hash['start'] = 'start'
  @_hash
end

.nullablesObject

An array for nullable fields



42
43
44
# File 'lib/walmart_ap_is/models/window.rb', line 42

def self.nullables
  []
end

.optionalsObject

An array for optional fields



35
36
37
38
39
# File 'lib/walmart_ap_is/models/window.rb', line 35

def self.optionals
  %w[
    editable_until
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



108
109
110
111
112
# File 'lib/walmart_ap_is/models/window.rb', line 108

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} editable_until: #{@editable_until.inspect}, mend: #{@mend.inspect}, start:"\
  " #{@start.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_editable_untilObject



88
89
90
# File 'lib/walmart_ap_is/models/window.rb', line 88

def to_custom_editable_until
  DateTimeHelper.to_rfc3339(editable_until)
end

#to_custom_mendObject



92
93
94
# File 'lib/walmart_ap_is/models/window.rb', line 92

def to_custom_mend
  DateTimeHelper.to_rfc3339(mend)
end

#to_custom_startObject



96
97
98
# File 'lib/walmart_ap_is/models/window.rb', line 96

def to_custom_start
  DateTimeHelper.to_rfc3339(start)
end

#to_sObject

Provides a human-readable string representation of the object.



101
102
103
104
105
# File 'lib/walmart_ap_is/models/window.rb', line 101

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} editable_until: #{@editable_until}, mend: #{@mend}, start: #{@start},"\
  " additional_properties: #{@additional_properties}>"
end