Class: ApiReference::Tier
- Defined in:
- lib/api_reference/models/tier.rb
Overview
Configuration for a single tier
Instance Attribute Summary collapse
-
#first_unit ⇒ Float
Exclusive tier starting value.
-
#last_unit ⇒ Float
Inclusive tier ending value.
-
#unit_amount ⇒ String
Amount per unit.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(first_unit:, unit_amount:, last_unit: SKIP) ⇒ Tier
constructor
A new instance of Tier.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(first_unit:, unit_amount:, last_unit: SKIP) ⇒ Tier
Returns a new instance of Tier.
48 49 50 51 52 |
# File 'lib/api_reference/models/tier.rb', line 48 def initialize(first_unit:, unit_amount:, last_unit: SKIP) @first_unit = first_unit @last_unit = last_unit unless last_unit == SKIP @unit_amount = unit_amount end |
Instance Attribute Details
#first_unit ⇒ Float
Exclusive tier starting value
14 15 16 |
# File 'lib/api_reference/models/tier.rb', line 14 def first_unit @first_unit end |
#last_unit ⇒ Float
Inclusive tier ending value. This value is null if and only if this is the last tier.
19 20 21 |
# File 'lib/api_reference/models/tier.rb', line 19 def last_unit @last_unit end |
#unit_amount ⇒ String
Amount per unit
23 24 25 |
# File 'lib/api_reference/models/tier.rb', line 23 def unit_amount @unit_amount end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/api_reference/models/tier.rb', line 55 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. first_unit = hash.key?('first_unit') ? hash['first_unit'] : nil unit_amount = hash.key?('unit_amount') ? hash['unit_amount'] : nil last_unit = hash.key?('last_unit') ? hash['last_unit'] : SKIP # Create object from extracted values. Tier.new(first_unit: first_unit, unit_amount: unit_amount, last_unit: last_unit) end |
.names ⇒ Object
A mapping from model property names to API property names.
26 27 28 29 30 31 32 |
# File 'lib/api_reference/models/tier.rb', line 26 def self.names @_hash = {} if @_hash.nil? @_hash['first_unit'] = 'first_unit' @_hash['last_unit'] = 'last_unit' @_hash['unit_amount'] = 'unit_amount' @_hash end |
.nullables ⇒ Object
An array for nullable fields
42 43 44 45 46 |
# File 'lib/api_reference/models/tier.rb', line 42 def self.nullables %w[ last_unit ] end |
.optionals ⇒ Object
An array for optional fields
35 36 37 38 39 |
# File 'lib/api_reference/models/tier.rb', line 35 def self.optionals %w[ last_unit ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/api_reference/models/tier.rb', line 71 def self.validate(value) if value.instance_of? self return ( APIHelper.valid_type?(value.first_unit, ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value.unit_amount, ->(val) { val.instance_of? String }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['first_unit'], ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value['unit_amount'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
99 100 101 102 103 |
# File 'lib/api_reference/models/tier.rb', line 99 def inspect class_name = self.class.name.split('::').last "<#{class_name} first_unit: #{@first_unit.inspect}, last_unit: #{@last_unit.inspect},"\ " unit_amount: #{@unit_amount.inspect}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
92 93 94 95 96 |
# File 'lib/api_reference/models/tier.rb', line 92 def to_s class_name = self.class.name.split('::').last "<#{class_name} first_unit: #{@first_unit}, last_unit: #{@last_unit}, unit_amount:"\ " #{@unit_amount}>" end |