Class: Bouncie::Entity

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

Overview

Abstract base class for objects returned from API requests. Parses dates, converts keys to underscore.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Entity

Returns a new instance of Entity.



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

def initialize(data)
  transformed = data.transform_keys { |k| k.to_s.underscore.to_sym }
  @data = massage_data(transformed)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/bouncie/entity.rb', line 13

def method_missing(method_name, *args, &block)
  if @data.key?(method_name)
    @data[method_name]
  else
    super
  end
end

Instance Method Details

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

Returns:

  • (Boolean)


21
22
23
# File 'lib/bouncie/entity.rb', line 21

def respond_to_missing?(method_name, _include_private = false)
  @data.key?(method_name)
end