Class: ApiReference::Product
- Defined in:
- lib/api_reference/models/product.rb
Overview
Product Model.
Instance Attribute Summary collapse
-
#created_at ⇒ DateTime
TODO: Write general description for this method.
-
#id ⇒ String
TODO: Write general description for this method.
-
#name ⇒ String
TODO: Write general description for this method.
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(created_at:, id:, name:, additional_properties: nil) ⇒ Product
constructor
A new instance of Product.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_created_at ⇒ Object
-
#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(created_at:, id:, name:, additional_properties: nil) ⇒ Product
Returns a new instance of Product.
44 45 46 47 48 49 50 51 52 |
# File 'lib/api_reference/models/product.rb', line 44 def initialize(created_at:, id:, name:, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @created_at = created_at @id = id @name = name @additional_properties = additional_properties end |
Instance Attribute Details
#created_at ⇒ DateTime
TODO: Write general description for this method
15 16 17 |
# File 'lib/api_reference/models/product.rb', line 15 def created_at @created_at end |
#id ⇒ String
TODO: Write general description for this method
19 20 21 |
# File 'lib/api_reference/models/product.rb', line 19 def id @id end |
#name ⇒ String
TODO: Write general description for this method
23 24 25 |
# File 'lib/api_reference/models/product.rb', line 23 def name @name 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 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/api_reference/models/product.rb', line 55 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 id = hash.key?('id') ? hash['id'] : nil name = hash.key?('name') ? hash['name'] : 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. Product.new(created_at: created_at, id: id, name: name, additional_properties: additional_properties) 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/product.rb', line 26 def self.names @_hash = {} if @_hash.nil? @_hash['created_at'] = 'created_at' @_hash['id'] = 'id' @_hash['name'] = 'name' @_hash end |
.nullables ⇒ Object
An array for nullable fields
40 41 42 |
# File 'lib/api_reference/models/product.rb', line 40 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
35 36 37 |
# File 'lib/api_reference/models/product.rb', line 35 def self.optionals [] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/api_reference/models/product.rb', line 85 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.id, ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value.name, ->(val) { val.instance_of? String }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['created_at'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['id'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['name'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
117 118 119 120 121 |
# File 'lib/api_reference/models/product.rb', line 117 def inspect class_name = self.class.name.split('::').last "<#{class_name} created_at: #{@created_at.inspect}, id: #{@id.inspect}, name:"\ " #{@name.inspect}, additional_properties: #{@additional_properties}>" end |
#to_custom_created_at ⇒ Object
79 80 81 |
# File 'lib/api_reference/models/product.rb', line 79 def to_custom_created_at DateTimeHelper.to_rfc3339(created_at) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
110 111 112 113 114 |
# File 'lib/api_reference/models/product.rb', line 110 def to_s class_name = self.class.name.split('::').last "<#{class_name} created_at: #{@created_at}, id: #{@id}, name: #{@name},"\ " additional_properties: #{@additional_properties}>" end |