Class: ApiReference::PlanVersion

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

Overview

The PlanVersion resource represents the prices and adjustments present on a specific version of a plan.

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(created_at:, version:, plan_phases:, prices:, adjustments:, additional_properties: nil) ⇒ PlanVersion

Returns a new instance of PlanVersion.



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/api_reference/models/plan_version.rb', line 59

def initialize(created_at:, version:, plan_phases:, prices:, adjustments:,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @created_at = created_at
  @version = version
  @plan_phases = plan_phases
  @prices = prices
  @adjustments = adjustments
  @additional_properties = additional_properties
end

Instance Attribute Details

#adjustmentsArray[Object]

Adjustments for this plan. If the plan has phases, this includes adjustments across all phases of the plan.

Returns:

  • (Array[Object])


34
35
36
# File 'lib/api_reference/models/plan_version.rb', line 34

def adjustments
  @adjustments
end

#created_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


16
17
18
# File 'lib/api_reference/models/plan_version.rb', line 16

def created_at
  @created_at
end

#plan_phasesArray[PlanVersionPhase]

TODO: Write general description for this method

Returns:



24
25
26
# File 'lib/api_reference/models/plan_version.rb', line 24

def plan_phases
  @plan_phases
end

#pricesArray[Object]

Prices for this plan. If the plan has phases, this includes prices across all phases of the plan.

Returns:

  • (Array[Object])


29
30
31
# File 'lib/api_reference/models/plan_version.rb', line 29

def prices
  @prices
end

#versionInteger

TODO: Write general description for this method

Returns:

  • (Integer)


20
21
22
# File 'lib/api_reference/models/plan_version.rb', line 20

def version
  @version
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
103
104
105
106
107
108
109
110
111
112
# File 'lib/api_reference/models/plan_version.rb', line 73

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  version = hash.key?('version') ? hash['version'] : nil
  # Parameter is an array, so we need to iterate through it
  plan_phases = nil
  unless hash['plan_phases'].nil?
    plan_phases = []
    hash['plan_phases'].each do |structure|
      plan_phases << (PlanVersionPhase.from_hash(structure) if structure)
    end
  end

  plan_phases = nil unless hash.key?('plan_phases')
  prices = hash.key?('prices') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Price3), hash['prices']
  ) : nil
  adjustments = hash.key?('adjustments') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Adjustment3), hash['adjustments']
  ) : 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.
  PlanVersion.new(created_at: created_at,
                  version: version,
                  plan_phases: plan_phases,
                  prices: prices,
                  adjustments: adjustments,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
# File 'lib/api_reference/models/plan_version.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['created_at'] = 'created_at'
  @_hash['version'] = 'version'
  @_hash['plan_phases'] = 'plan_phases'
  @_hash['prices'] = 'prices'
  @_hash['adjustments'] = 'adjustments'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
56
57
# File 'lib/api_reference/models/plan_version.rb', line 53

def self.nullables
  %w[
    plan_phases
  ]
end

.optionalsObject

An array for optional fields



48
49
50
# File 'lib/api_reference/models/plan_version.rb', line 48

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (PlanVersion | Hash)

    value against the validation is performed.



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
145
146
147
148
149
150
151
152
153
154
# File 'lib/api_reference/models/plan_version.rb', line 120

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.created_at,
                            ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.version,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.plan_phases,
                              ->(val) { PlanVersionPhase.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) and
        UnionTypeLookUp.get(:Price3)
                       .validate(value.prices) and
        UnionTypeLookUp.get(:Adjustment3)
                       .validate(value.adjustments)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['created_at'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['version'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['plan_phases'],
                            ->(val) { PlanVersionPhase.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
      UnionTypeLookUp.get(:Price3)
                     .validate(value['prices']) and
      UnionTypeLookUp.get(:Adjustment3)
                     .validate(value['adjustments'])
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



165
166
167
168
169
170
# File 'lib/api_reference/models/plan_version.rb', line 165

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} created_at: #{@created_at.inspect}, version: #{@version.inspect},"\
  " plan_phases: #{@plan_phases.inspect}, prices: #{@prices.inspect}, adjustments:"\
  " #{@adjustments.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_created_atObject



114
115
116
# File 'lib/api_reference/models/plan_version.rb', line 114

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_sObject

Provides a human-readable string representation of the object.



157
158
159
160
161
162
# File 'lib/api_reference/models/plan_version.rb', line 157

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} created_at: #{@created_at}, version: #{@version}, plan_phases:"\
  " #{@plan_phases}, prices: #{@prices}, adjustments: #{@adjustments}, additional_properties:"\
  " #{@additional_properties}>"
end