Class: GuestyAPI::Entities::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/guesty_api/entities/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/guesty_api/entities/base.rb', line 8

def initialize(payload)
  @raw_data = payload
  @methods = payload.keys.map(&:to_sym)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



13
14
15
16
# File 'lib/guesty_api/entities/base.rb', line 13

def method_missing(method, *)
  super unless @methods.include? method
  @raw_data[method.to_s]
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



6
7
8
# File 'lib/guesty_api/entities/base.rb', line 6

def raw_data
  @raw_data
end

Instance Method Details

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/guesty_api/entities/base.rb', line 18

def respond_to_missing?(method, *)
  return true if @methods.include? method

  super
end