Class: SwaggerPetstoreOpenApi30::Pet

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/swagger_petstore_open_api30/models/pet.rb

Overview

Pet 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(name:, photo_urls:, id: SKIP, category: SKIP, tags: SKIP, status: SKIP, additional_properties: nil) ⇒ Pet

Returns a new instance of Pet.



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 63

def initialize(name:, photo_urls:, id: SKIP, category: SKIP, tags: SKIP,
               status: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @id = id unless id == SKIP
  @name = name
  @category = category unless category == SKIP
  @photo_urls = photo_urls
  @tags = tags unless tags == SKIP
  @status = status unless status == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#categoryCategory

TODO: Write general description for this method

Returns:



22
23
24
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 22

def category
  @category
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


14
15
16
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 14

def id
  @id
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


18
19
20
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 18

def name
  @name
end

#photo_urlsArray[String]

TODO: Write general description for this method

Returns:

  • (Array[String])


26
27
28
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 26

def photo_urls
  @photo_urls
end

#statusPetStatus

pet status in the store

Returns:



34
35
36
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 34

def status
  @status
end

#tagsArray[Tag]

TODO: Write general description for this method

Returns:



30
31
32
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 30

def tags
  @tags
end

Class Method Details

.from_element(root) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 115

def self.from_element(root)
  name = XmlUtilities.from_element(root, 'name', String)
  photo_urls = XmlUtilities.from_element_to_array(
    root, 'photoUrl', String, wrapping_element_name: 'photoUrls'
  )
  id = XmlUtilities.from_element(root, 'id', Integer)
  category = XmlUtilities.from_element(root, 'category', Category)
  tags = XmlUtilities.from_element_to_array(root, 'tag', Tag,
                                            wrapping_element_name: 'tags')
  status = XmlUtilities.from_element(root, 'status', String)

  new(name: name,
      photo_urls: photo_urls,
      id: id,
      category: category,
      tags: tags,
      status: status,
      additional_properties: additional_properties)
end

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
113
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 78

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  photo_urls = hash.key?('photoUrls') ? hash['photoUrls'] : nil
  id = hash.key?('id') ? hash['id'] : SKIP
  category = Category.from_hash(hash['category']) if hash['category']
  # Parameter is an array, so we need to iterate through it
  tags = nil
  unless hash['tags'].nil?
    tags = []
    hash['tags'].each do |structure|
      tags << (Tag.from_hash(structure) if structure)
    end
  end

  tags = SKIP unless hash.key?('tags')
  status = hash.key?('status') ? hash['status'] : SKIP

  # 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.
  Pet.new(name: name,
          photo_urls: photo_urls,
          id: id,
          category: category,
          tags: tags,
          status: status,
          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
46
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['category'] = 'category'
  @_hash['photo_urls'] = 'photoUrls'
  @_hash['tags'] = 'tags'
  @_hash['status'] = 'status'
  @_hash
end

.nullablesObject

An array for nullable fields



59
60
61
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 59

def self.nullables
  []
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
55
56
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 49

def self.optionals
  %w[
    id
    category
    tags
    status
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



161
162
163
164
165
166
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 161

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, name: #{@name.inspect}, category: #{@category.inspect},"\
  " photo_urls: #{@photo_urls.inspect}, tags: #{@tags.inspect}, status: #{@status.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



153
154
155
156
157
158
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 153

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, name: #{@name}, category: #{@category}, photo_urls:"\
  " #{@photo_urls}, tags: #{@tags}, status: #{@status}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_xml_element(doc, root_name) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 135

def to_xml_element(doc, root_name)
  root = doc.create_element(root_name)

  XmlUtilities.add_as_subelement(doc, root, 'name', name)
  XmlUtilities.add_array_as_subelement(doc, root, 'photoUrl', photo_urls,
                                       wrapping_element_name: 'photoUrls')
  XmlUtilities.add_as_subelement(doc, root, 'id', id)
  XmlUtilities.add_as_subelement(doc, root, 'category', category)
  XmlUtilities.add_array_as_subelement(doc, root, 'tag', tags,
                                       wrapping_element_name: 'tags')
  XmlUtilities.add_as_subelement(doc, root, 'status', status)
  XmlUtilities.add_as_subelement(doc, root, 'additional_properties',
                                 additional_properties)

  root
end