Class: GPS::Response
- Inherits:
-
Object
- Object
- GPS::Response
- Defined in:
- lib/gpsd/response.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #classname ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method, *args) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gpsd/response.rb', line 8 def initialize(response) if response.is_a?(String) @payload = MultiJson.load(response) elsif response.is_a?(Hash) @payload = response else raise GPS::ProtocolError.new("Invalid response data") end @payload['time'] = Time.parse(@payload['time']) if @payload.has_key?('time') case @payload['class'] when 'POLL' @payload['tpv'] = @payload['tpv'].collect{|i| GPS::Response.new(i) } @payload['sky'] = @payload['sky'].collect{|i| GPS::Response.new(i) } end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/gpsd/response.rb', line 31 def method_missing(method, *args) if @payload.has_key?(method.to_s) return @payload[method.to_s] else super end end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
6 7 8 |
# File 'lib/gpsd/response.rb', line 6 def payload @payload end |
Instance Method Details
#[](key) ⇒ Object
39 40 41 42 43 |
# File 'lib/gpsd/response.rb', line 39 def [](key) return @payload[key.to_s] rescue return nil end |
#classname ⇒ Object
45 46 47 48 49 |
# File 'lib/gpsd/response.rb', line 45 def classname() return @payload['class'].to_sym rescue return nil end |