Class: SuggestGrid::Metadata

Inherits:
BaseModel show all
Defined in:
lib/suggestgrid/models/metadata.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(hash) ⇒ Metadata

Returns a new instance of Metadata.



18
19
20
21
22
23
24
25
# File 'lib/suggestgrid/models/metadata.rb', line 18

def initialize(hash)
  if !hash['id']
    hash['id'] = nil
  end
  hash.each { |name, value|
    instance_variable_set("@#{name}", value)
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object

Use to allow additional model properties



33
34
35
36
37
38
39
40
41
42
# File 'lib/suggestgrid/models/metadata.rb', line 33

def method_missing(method_sym, *arguments, &block)
  method = method_sym.to_s
  if method.end_with? '='
    instance_variable_set("@%s" % [method.chomp('=')], arguments.first)
  elsif instance_variable_defined?("@#{method}") && arguments.empty?
    instance_variable_get("@#{method}")
  else
    super
  end
end

Instance Attribute Details

#idString

The id of the metadata of a user or an item.

Returns:



7
8
9
# File 'lib/suggestgrid/models/metadata.rb', line 7

def id
  @id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash



28
29
30
# File 'lib/suggestgrid/models/metadata.rb', line 28

def self.from_hash(hash)
  Metadata.new(hash)
end

.namesObject

A mapping from model property names to API property names



10
11
12
13
14
15
16
# File 'lib/suggestgrid/models/metadata.rb', line 10

def self.names
  if @_hash.nil?
    @_hash = {}
    @_hash["id"] = "id"
  end
  @_hash
end

Instance Method Details

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Override for additional model properties

Returns:

  • (Boolean)


45
46
47
# File 'lib/suggestgrid/models/metadata.rb', line 45

def respond_to?(method_sym, include_private=false)
  instance_variable_defined?("@#{method_sym}") ? true : super
end