Class: ApiReference::AdjustmentInterval

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/adjustment_interval.rb

Overview

AdjustmentInterval Model.

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(id:, adjustment:, start_date:, end_date:, applies_to_price_interval_ids:, additional_properties: nil) ⇒ AdjustmentInterval

Returns a new instance of AdjustmentInterval.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/api_reference/models/adjustment_interval.rb', line 57

def initialize(id:, adjustment:, start_date:, end_date:,
               applies_to_price_interval_ids:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @id = id
  @adjustment = adjustment
  @start_date = start_date
  @end_date = end_date
  @applies_to_price_interval_ids = applies_to_price_interval_ids
  @additional_properties = additional_properties
end

Instance Attribute Details

#adjustmentObject

TODO: Write general description for this method

Returns:

  • (Object)


19
20
21
# File 'lib/api_reference/models/adjustment_interval.rb', line 19

def adjustment
  @adjustment
end

#applies_to_price_interval_idsArray[String]

The price interval IDs that this adjustment applies to.

Returns:

  • (Array[String])


31
32
33
# File 'lib/api_reference/models/adjustment_interval.rb', line 31

def applies_to_price_interval_ids
  @applies_to_price_interval_ids
end

#end_dateDateTime

The end date of the adjustment interval.

Returns:

  • (DateTime)


27
28
29
# File 'lib/api_reference/models/adjustment_interval.rb', line 27

def end_date
  @end_date
end

#idString

TODO: Write general description for this method

Returns:

  • (String)


15
16
17
# File 'lib/api_reference/models/adjustment_interval.rb', line 15

def id
  @id
end

#start_dateDateTime

The start date of the adjustment interval.

Returns:

  • (DateTime)


23
24
25
# File 'lib/api_reference/models/adjustment_interval.rb', line 23

def start_date
  @start_date
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/api_reference/models/adjustment_interval.rb', line 71

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  adjustment = hash.key?('adjustment') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Adjustment), hash['adjustment']
  ) : nil
  start_date = if hash.key?('start_date')
                 (DateTimeHelper.from_rfc3339(hash['start_date']) if hash['start_date'])
               end
  end_date = if hash.key?('end_date')
               (DateTimeHelper.from_rfc3339(hash['end_date']) if hash['end_date'])
             end
  applies_to_price_interval_ids =
    hash.key?('applies_to_price_interval_ids') ? hash['applies_to_price_interval_ids'] : nil

  # 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.
  AdjustmentInterval.new(id: id,
                         adjustment: adjustment,
                         start_date: start_date,
                         end_date: end_date,
                         applies_to_price_interval_ids: applies_to_price_interval_ids,
                         additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
42
43
# File 'lib/api_reference/models/adjustment_interval.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['adjustment'] = 'adjustment'
  @_hash['start_date'] = 'start_date'
  @_hash['end_date'] = 'end_date'
  @_hash['applies_to_price_interval_ids'] =
    'applies_to_price_interval_ids'
  @_hash
end

.nullablesObject

An array for nullable fields



51
52
53
54
55
# File 'lib/api_reference/models/adjustment_interval.rb', line 51

def self.nullables
  %w[
    end_date
  ]
end

.optionalsObject

An array for optional fields



46
47
48
# File 'lib/api_reference/models/adjustment_interval.rb', line 46

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/api_reference/models/adjustment_interval.rb', line 114

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:Adjustment)
                       .validate(value.adjustment) and
        APIHelper.valid_type?(value.start_date,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.end_date,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.applies_to_price_interval_ids,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:Adjustment)
                     .validate(value['adjustment']) and
      APIHelper.valid_type?(value['start_date'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['end_date'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['applies_to_price_interval_ids'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



155
156
157
158
159
160
161
# File 'lib/api_reference/models/adjustment_interval.rb', line 155

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, adjustment: #{@adjustment.inspect}, start_date:"\
  " #{@start_date.inspect}, end_date: #{@end_date.inspect}, applies_to_price_interval_ids:"\
  " #{@applies_to_price_interval_ids.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_custom_end_dateObject



108
109
110
# File 'lib/api_reference/models/adjustment_interval.rb', line 108

def to_custom_end_date
  DateTimeHelper.to_rfc3339(end_date)
end

#to_custom_start_dateObject



104
105
106
# File 'lib/api_reference/models/adjustment_interval.rb', line 104

def to_custom_start_date
  DateTimeHelper.to_rfc3339(start_date)
end

#to_sObject

Provides a human-readable string representation of the object.



147
148
149
150
151
152
# File 'lib/api_reference/models/adjustment_interval.rb', line 147

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, adjustment: #{@adjustment}, start_date: #{@start_date},"\
  " end_date: #{@end_date}, applies_to_price_interval_ids: #{@applies_to_price_interval_ids},"\
  " additional_properties: #{@additional_properties}>"
end