Class: Bouncie::Entity
- Inherits:
-
Object
- Object
- Bouncie::Entity
- Defined in:
- lib/bouncie/entity.rb
Overview
Abstract base class for objects returned from API requests. Parses dates, converts keys to underscore.
Direct Known Subclasses
DeviceEvents::ConnectEvent, DeviceEvents::DisconnectEvent, Trip, User, Vehicle, VehicleHealthEvents::BatteryEvent, VehicleHealthEvents::MilEvent, VehicleTripEvents::TripDataEvent, VehicleTripEvents::TripEndEvent, VehicleTripEvents::TripMetricsEvent, VehicleTripEvents::TripStartEvent
Instance Method Summary collapse
-
#initialize(data) ⇒ Entity
constructor
A new instance of Entity.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
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
21 22 23 |
# File 'lib/bouncie/entity.rb', line 21 def respond_to_missing?(method_name, _include_private = false) @data.key?(method_name) end |