Class: Artoo::Adaptors::Sphero
- Defined in:
- lib/artoo/adaptors/sphero.rb
Overview
Connect to a Sphero (gosphero.com)
Constant Summary collapse
- RETRY_COUNT =
5
Instance Attribute Summary collapse
-
#sphero ⇒ Object
readonly
Returns the value of attribute sphero.
Attributes inherited from Adaptor
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
- #finalize ⇒ Object
- #method_missing(method_name, *arguments, &block) ⇒ Object
Methods inherited from Adaptor
#connect_to, #connect_to_serial, #connect_to_tcp, #connect_to_udp, #connected?, #initialize, #reconnect
Constructor Details
This class inherits a constructor from Artoo::Adaptors::Adaptor
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
41 42 43 |
# File 'lib/artoo/adaptors/sphero.rb', line 41 def method_missing(method_name, *arguments, &block) sphero.send(method_name, *arguments, &block) end |
Instance Attribute Details
#sphero ⇒ Object (readonly)
Returns the value of attribute sphero.
9 10 11 |
# File 'lib/artoo/adaptors/sphero.rb', line 9 def sphero @sphero end |
Instance Method Details
#connect ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/artoo/adaptors/sphero.rb', line 17 def connect @retries_left = RETRY_COUNT require 'sphero' unless defined?(::Sphero) begin @sphero = ::Sphero.new(connect_to) super return true rescue Errno::EBUSY => e @retries_left -= 1 if @retries_left > 0 retry else Logger.error e. Logger.error e.backtrace.inspect return false end end end |
#disconnect ⇒ Object
36 37 38 39 |
# File 'lib/artoo/adaptors/sphero.rb', line 36 def disconnect sphero.close super end |
#finalize ⇒ Object
11 12 13 14 15 |
# File 'lib/artoo/adaptors/sphero.rb', line 11 def finalize if connected? sphero.close end end |