Class: TeslaAPI::Data
- Inherits:
-
Object
- Object
- TeslaAPI::Data
- Defined in:
- lib/tesla-api/data.rb
Overview
Base class for all data responses from the HTTP API
Defines an instance_variable? method for each instance_variable defined allowing for methods such as #charge_port_open?
Also overrides #inspect to elimiante the back reference to the connection object
Direct Known Subclasses
ChargeState, ClimateState, DriveState, GUISettings, Vehicle, VehicleState
Instance Method Summary collapse
- #inspect ⇒ Object
- #ivar_from_data(name, data_key, data) ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/tesla-api/data.rb', line 9 def method_missing(method_name, *args, &block) if has_query_ivar_method?(method_name) instance_variable_get(ivar_for_method_name(method_name)) else super end end |
Instance Method Details
#inspect ⇒ Object
21 22 23 |
# File 'lib/tesla-api/data.rb', line 21 def inspect "#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{inspect_ivars}>" end |
#ivar_from_data(name, data_key, data) ⇒ Object
25 26 27 28 29 |
# File 'lib/tesla-api/data.rb', line 25 def ivar_from_data(name, data_key, data) instance_variable_set("@#{name}".to_sym, data[data_key]) self.class.send(:attr_reader, name.to_sym) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
17 18 19 |
# File 'lib/tesla-api/data.rb', line 17 def respond_to_missing?(method_name, include_private = false) has_query_ivar_method?(method_name) || super end |