Class: Vonage::Entity

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil) ⇒ Entity

Returns a new instance of Entity.



7
8
9
# File 'lib/vonage/entity.rb', line 7

def initialize(attributes = nil)
  @attributes = attributes || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



23
24
25
26
27
# File 'lib/vonage/entity.rb', line 23

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

  @attributes[name]
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



37
38
39
# File 'lib/vonage/entity.rb', line 37

def attributes
  @attributes
end

Instance Method Details

#==(entity) ⇒ Object



29
30
31
# File 'lib/vonage/entity.rb', line 29

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

#[](key) ⇒ Object



11
12
13
# File 'lib/vonage/entity.rb', line 11

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

#[]=(key, value) ⇒ Object



15
16
17
# File 'lib/vonage/entity.rb', line 15

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

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



39
40
41
42
43
# File 'lib/vonage/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)


19
20
21
# File 'lib/vonage/entity.rb', line 19

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

#to_hObject



33
34
35
# File 'lib/vonage/entity.rb', line 33

def to_h
  @attributes
end