Class: SuggestGrid::Metadata

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

Overview

Metadata of a user or an item. Id parameter is required for all metadata. Metadata may have other parameters with string, number, or boolean values.

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.



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

def initialize(hash)
  if !hash['id']
    hash['id'] = nilc
  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



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

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:



10
11
12
# File 'lib/suggestgrid/models/metadata.rb', line 10

def id
  @id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

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

.namesObject

A mapping from model property names to API property names.



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

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

Instance Method Details

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

Override for additional model properties

Returns:

  • (Boolean)


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

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