Class: CypressTestApi::Item

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/cypress_test_api/models/item.rb

Overview

Item 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(id = nil, name = nil, date = nil, date_time = nil, decimal = nil, long = nil, bool = nil, custom_enum = nil, json_object = nil, animal = nil, map = nil, status = SKIP) ⇒ Item

Returns a new instance of Item.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cypress_test_api/models/item.rb', line 91

def initialize(id = nil, name = nil, date = nil, date_time = nil,
               decimal = nil, long = nil, bool = nil, custom_enum = nil,
               json_object = nil, animal = nil, map = nil, status = SKIP)
  @id = id
  @name = name
  @date = date
  @date_time = date_time
  @decimal = decimal
  @long = long
  @bool = bool
  @custom_enum = custom_enum
  @status = status unless status == SKIP
  @json_object = json_object
  @animal = animal
  @map = map
end

Instance Attribute Details

#animalObject

A generic JSON object

Returns:

  • (Object)


55
56
57
# File 'lib/cypress_test_api/models/item.rb', line 55

def animal
  @animal
end

#boolTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


39
40
41
# File 'lib/cypress_test_api/models/item.rb', line 39

def bool
  @bool
end

#custom_enumCustomEnum

TODO: Write general description for this method

Returns:



43
44
45
# File 'lib/cypress_test_api/models/item.rb', line 43

def custom_enum
  @custom_enum
end

#dateDate

TODO: Write general description for this method

Returns:

  • (Date)


23
24
25
# File 'lib/cypress_test_api/models/item.rb', line 23

def date
  @date
end

#date_timeDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


27
28
29
# File 'lib/cypress_test_api/models/item.rb', line 27

def date_time
  @date_time
end

#decimalFloat

TODO: Write general description for this method

Returns:

  • (Float)


31
32
33
# File 'lib/cypress_test_api/models/item.rb', line 31

def decimal
  @decimal
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


15
16
17
# File 'lib/cypress_test_api/models/item.rb', line 15

def id
  @id
end

#json_objectObject

A generic JSON object

Returns:

  • (Object)


51
52
53
# File 'lib/cypress_test_api/models/item.rb', line 51

def json_object
  @json_object
end

#longInteger

TODO: Write general description for this method

Returns:

  • (Integer)


35
36
37
# File 'lib/cypress_test_api/models/item.rb', line 35

def long
  @long
end

#mapHash[String, Message]

A generic JSON object

Returns:



59
60
61
# File 'lib/cypress_test_api/models/item.rb', line 59

def map
  @map
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/cypress_test_api/models/item.rb', line 19

def name
  @name
end

#statusStatusEnum

TODO: Write general description for this method

Returns:



47
48
49
# File 'lib/cypress_test_api/models/item.rb', line 47

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/cypress_test_api/models/item.rb', line 109

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  date = hash.key?('date') ? hash['date'] : nil
  date_time = if hash.key?('dateTime')
                (DateTimeHelper.from_rfc3339(hash['dateTime']) if hash['dateTime'])
              end
  decimal = hash.key?('decimal') ? hash['decimal'] : nil
  long = hash.key?('long') ? hash['long'] : nil
  bool = hash.key?('bool') ? hash['bool'] : nil
  custom_enum = hash.key?('CustomEnum') ? hash['CustomEnum'] : nil
  json_object = hash.key?('jsonObject') ? hash['jsonObject'] : nil
  animal = hash.key?('Animal') ? hash['Animal'] : nil
  map = Message.from_hash(hash['Map']) if hash['Map']

  map = nil unless hash.key?('Map')
  status = hash.key?('status') ? hash['status'] : SKIP

  # Create object from extracted values.
  Item.new(id,
           name,
           date,
           date_time,
           decimal,
           long,
           bool,
           custom_enum,
           json_object,
           animal,
           map,
           status)
end

.namesObject

A mapping from model property names to API property names.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cypress_test_api/models/item.rb', line 62

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['date'] = 'date'
  @_hash['date_time'] = 'dateTime'
  @_hash['decimal'] = 'decimal'
  @_hash['long'] = 'long'
  @_hash['bool'] = 'bool'
  @_hash['custom_enum'] = 'CustomEnum'
  @_hash['status'] = 'status'
  @_hash['json_object'] = 'jsonObject'
  @_hash['animal'] = 'Animal'
  @_hash['map'] = 'Map'
  @_hash
end

.nullablesObject

An array for nullable fields



87
88
89
# File 'lib/cypress_test_api/models/item.rb', line 87

def self.nullables
  []
end

.optionalsObject

An array for optional fields



80
81
82
83
84
# File 'lib/cypress_test_api/models/item.rb', line 80

def self.optionals
  %w[
    status
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



158
159
160
161
162
163
164
# File 'lib/cypress_test_api/models/item.rb', line 158

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, name: #{@name.inspect}, date: #{@date.inspect},"\
  " date_time: #{@date_time.inspect}, decimal: #{@decimal.inspect}, long: #{@long.inspect},"\
  " bool: #{@bool.inspect}, custom_enum: #{@custom_enum.inspect}, status: #{@status.inspect},"\
  " json_object: #{@json_object.inspect}, animal: #{@animal.inspect}, map: #{@map.inspect}>"
end

#to_custom_date_timeObject



145
146
147
# File 'lib/cypress_test_api/models/item.rb', line 145

def to_custom_date_time
  DateTimeHelper.to_rfc3339(date_time)
end

#to_sObject

Provides a human-readable string representation of the object.



150
151
152
153
154
155
# File 'lib/cypress_test_api/models/item.rb', line 150

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, name: #{@name}, date: #{@date}, date_time: #{@date_time},"\
  " decimal: #{@decimal}, long: #{@long}, bool: #{@bool}, custom_enum: #{@custom_enum},"\
  " status: #{@status}, json_object: #{@json_object}, animal: #{@animal}, map: #{@map}>"
end