Class: Nexmo::Entity

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nexmo/entity.rb

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Entity

Returns a new instance of Entity.


5
6
7
# File 'lib/nexmo/entity.rb', line 5

def initialize(**kwargs)
  @attributes = kwargs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object


21
22
23
24
25
# File 'lib/nexmo/entity.rb', line 21

def method_missing(name, *args)
  return super unless @attributes.key?(name)

  @attributes[name]
end

Instance Method Details

#==(entity) ⇒ Object


27
28
29
# File 'lib/nexmo/entity.rb', line 27

def ==(entity)
  entity.class == self.class && entity.attributes == @attributes
end

#[](key) ⇒ Object


9
10
11
# File 'lib/nexmo/entity.rb', line 9

def [](key)
  @attributes[attribute_key(key)]
end

#[]=(key, value) ⇒ Object


13
14
15
# File 'lib/nexmo/entity.rb', line 13

def []=(key, value)
  @attributes[attribute_key(key)] = value
end

#each_pair(&block) ⇒ Object Also known as: each


39
40
41
42
43
# File 'lib/nexmo/entity.rb', line 39

def each_pair(&block)
  return to_enum(:each_pair) unless block

  @attributes.each_pair(&block)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/nexmo/entity.rb', line 17

def respond_to_missing?(name, include_private = false)
  @attributes.key?(name) or super
end

#to_hObject


31
32
33
# File 'lib/nexmo/entity.rb', line 31

def to_h
  @attributes
end