Class: Wajub::ApiObject

Inherits:
Object
  • Object
show all
Defined in:
lib/wajub/objects.rb

Direct Known Subclasses

Payment

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ApiObject

Returns a new instance of ApiObject.



5
6
7
# File 'lib/wajub/objects.rb', line 5

def initialize(data)
  @data = data.transform_keys(&:to_s)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/wajub/objects.rb', line 17

def method_missing(name, *args)
  return super if args.any? || name.end_with?('=')

  key = name.to_s
  return @data[key] if @data.key?(key)

  super
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/wajub/objects.rb', line 9

def [](key)
  @data[key.to_s]
end

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

Returns:

  • (Boolean)


26
27
28
# File 'lib/wajub/objects.rb', line 26

def respond_to_missing?(name, include_private = false)
  @data.key?(name.to_s) || super
end

#to_hObject



13
14
15
# File 'lib/wajub/objects.rb', line 13

def to_h
  @data.dup
end