Class: SuggestGrid::ItemsResponse
- Defined in:
- lib/suggest_grid/models/items_response.rb
Instance Attribute Summary collapse
-
#count ⇒ Long
The number of items in the response.
-
#items ⇒ List of Metadata
The total number of items available.
-
#total_count ⇒ Long
The total number of items available.
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.
Instance Method Summary collapse
-
#initialize(count = nil, total_count = nil, items = nil, additional_properties = {}) ⇒ ItemsResponse
constructor
A new instance of ItemsResponse.
Methods inherited from BaseModel
#method_missing, #respond_to?, #to_hash, #to_json
Constructor Details
#initialize(count = nil, total_count = nil, items = nil, additional_properties = {}) ⇒ ItemsResponse
Returns a new instance of ItemsResponse.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/suggest_grid/models/items_response.rb', line 28 def initialize(count = nil, total_count = nil, items = nil, additional_properties = {}) @count = count @total_count = total_count @items = items # Add additional model properties to the instance additional_properties.each {|name, value| instance_variable_set("@#{name}", value)} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SuggestGrid::BaseModel
Instance Attribute Details
#count ⇒ Long
The number of items in the response.
7 8 9 |
# File 'lib/suggest_grid/models/items_response.rb', line 7 def count @count end |
#items ⇒ List of Metadata
The total number of items available.
15 16 17 |
# File 'lib/suggest_grid/models/items_response.rb', line 15 def items @items end |
#total_count ⇒ Long
The total number of items available.
11 12 13 |
# File 'lib/suggest_grid/models/items_response.rb', line 11 def total_count @total_count end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/suggest_grid/models/items_response.rb', line 41 def self.from_hash(hash) if hash == nil nil else # Extract variables from the hash count = hash["count"] total_count = hash["total_count"] # Parameter is an array, so we need to iterate through it items = nil if hash["items"] != nil items = Array.new hash["items"].each{|structure| items << (Metadata.from_hash(structure) if structure)} end # Clean out expected properties from Hash names.values.each {|k| hash.delete(k)} # Create object from extracted values ItemsResponse.new(count, total_count, items, hash) end end |
.names ⇒ Object
A mapping from model property names to API property names
18 19 20 21 22 23 24 25 26 |
# File 'lib/suggest_grid/models/items_response.rb', line 18 def self.names if @hash.nil? @hash = {} @hash["count"] = "count" @hash["total_count"] = "total_count" @hash["items"] = "items" end @hash end |