Class: Agendrix::Nethris::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/agendrix/nethris/entity.rb

Direct Known Subclasses

Address, Employee, PhoneNumber

Instance Method Summary collapse

Constructor Details

#initialize(client, attributes) ⇒ Entity

Returns a new instance of Entity.



4
5
6
7
# File 'lib/agendrix/nethris/entity.rb', line 4

def initialize(client, attributes)
  @client = client
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/agendrix/nethris/entity.rb', line 15

def method_missing(method_name)
  method_name_s = method_name.to_s

  if @attributes.key?(method_name_s.upcase)
    @attributes[method_name_s.upcase]
  elsif @attributes.key?(method_name_s)
    @attributes[method_name_s]
  else
    super
  end
end

Instance Method Details

#inspectObject



9
10
11
12
13
# File 'lib/agendrix/nethris/entity.rb', line 9

def inspect
  variables = self.instance_variables - [:"@client"]
  variables.map! { |v| "#{v}=#{self.instance_eval(v.to_s)}" }
  "#<#{self.class} #{variables.join(', ')}>"
end

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

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/agendrix/nethris/entity.rb', line 27

def respond_to_missing?(method_name, include_private = false)
  method_name_s = method_name.to_s
  @attributes.key?(method_name_s) || @attributes.key?(method_name_s.upcase) || super
end