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 = nil, photo_urls = nil, id = SKIP, category = SKIP, tags = SKIP, status = SKIP) ⇒ Pet

Returns a new instance of Pet.



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

def initialize(name = nil, photo_urls = nil, id = SKIP, category = SKIP,
               tags = SKIP, status = SKIP)
  @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
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

#statusStatus1Enum

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



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 103

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,
      photo_urls,
      id,
      category,
      tags,
      status)
end

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

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 object from extracted values.
  Pet.new(name,
          photo_urls,
          id,
          category,
          tags,
          status)
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.



145
146
147
148
149
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 145

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}>"
end

#to_sObject

Provides a human-readable string representation of the object.



138
139
140
141
142
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 138

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}>"
end

#to_xml_element(doc, root_name) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/swagger_petstore_open_api30/models/pet.rb', line 122

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)

  root
end