Class: Artoo::Robot
- Inherits:
-
Object
- Object
- Artoo::Robot
- Extended by:
- Basic, ClassMethods
- Defined in:
- lib/artoo/robot.rb,
lib/artoo/robot_class_methods.rb
Overview
The most important class used by Artoo is Robot. This represents the primary interface for interacting with a collection of physical computing capabilities.
This module contains the class-level methods used by Artoo::Robot
Direct Known Subclasses
Defined Under Namespace
Modules: ClassMethods
Constant Summary
Constants included from Basic
Class Attribute Summary collapse
-
.connection_types ⇒ Object
Returns the value of attribute connection_types.
-
.device_types ⇒ Object
Returns the value of attribute device_types.
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#devices ⇒ Object
readonly
Returns the value of attribute devices.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from ClassMethods
Instance Method Summary collapse
-
#api_host ⇒ String
Api Host.
-
#api_port ⇒ String
Api Port.
-
#as_json ⇒ JSON
Robot.
-
#connection_types ⇒ Collection
Connection types.
-
#continue_work ⇒ Object
continue with the work.
-
#default_connection ⇒ Connection
Default connection.
-
#device_types ⇒ Collection
Device types.
-
#disconnect ⇒ Object
Terminate all connections.
-
#has_work?(period, interval) ⇒ Boolean
True if there is recurring work for the period and interval.
-
#initialize(params = {}) ⇒ Robot
constructor
Create new robot.
-
#inspect ⇒ String
Robot.
-
#pause_work ⇒ Object
pause the work.
-
#safe_name ⇒ String
Name without spaces and downcased.
-
#to_hash ⇒ Hash
Robot.
-
#work ⇒ Object
start doing the work.
-
#working_code ⇒ Proc
Current working code.
Methods included from Basic
Methods included from ClassMethods
api, begin_working, cli?, connection, device, handle_signals, is_running?, master, prepare_robots, running!, setup_interrupt, start_api, stopped!, test?, work!
Methods included from Events
#create_proxy_method, #on, #proxy_method_name
Methods included from Utility
#classify, #constantize, #current_class, #current_instance, #os, #random_string, #underscore
Constructor Details
#initialize(params = {}) ⇒ Robot
Create new robot
39 40 41 42 43 |
# File 'lib/artoo/robot.rb', line 39 def initialize(params={}) @name = params[:name] || "Robot #{random_string}" initialize_connections(params[:connections] || {}) initialize_devices(params[:devices] || {}) end |
Class Attribute Details
.connection_types ⇒ Object
Returns the value of attribute connection_types.
7 8 9 |
# File 'lib/artoo/robot_class_methods.rb', line 7 def connection_types @connection_types end |
.device_types ⇒ Object
Returns the value of attribute device_types.
7 8 9 |
# File 'lib/artoo/robot_class_methods.rb', line 7 def device_types @device_types end |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
32 33 34 |
# File 'lib/artoo/robot.rb', line 32 def connections @connections end |
#devices ⇒ Object (readonly)
Returns the value of attribute devices.
32 33 34 |
# File 'lib/artoo/robot.rb', line 32 def devices @devices end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/artoo/robot.rb', line 32 def name @name end |
Instance Method Details
#api_host ⇒ String
Returns Api Host.
51 52 53 |
# File 'lib/artoo/robot.rb', line 51 def api_host self.class.api_host end |
#api_port ⇒ String
Returns Api Port.
56 57 58 |
# File 'lib/artoo/robot.rb', line 56 def api_port self.class.api_port end |
#as_json ⇒ JSON
Returns robot.
123 124 125 |
# File 'lib/artoo/robot.rb', line 123 def as_json MultiJson.dump(to_hash) end |
#connection_types ⇒ Collection
Returns connection types.
91 92 93 |
# File 'lib/artoo/robot.rb', line 91 def connection_types current_class.connection_types end |
#continue_work ⇒ Object
continue with the work
75 76 77 78 |
# File 'lib/artoo/robot.rb', line 75 def continue_work Logger.info "Continuing work..." current_instance.timers.continue end |
#default_connection ⇒ Connection
Returns default connection.
86 87 88 |
# File 'lib/artoo/robot.rb', line 86 def default_connection connections.values.first end |
#device_types ⇒ Collection
Returns device types.
96 97 98 99 |
# File 'lib/artoo/robot.rb', line 96 def device_types current_class.device_types ||= [] current_class.device_types end |
#disconnect ⇒ Object
Terminate all connections
81 82 83 |
# File 'lib/artoo/robot.rb', line 81 def disconnect connections.each {|k, c| c.async.disconnect} end |
#has_work?(period, interval) ⇒ Boolean
Returns True if there is recurring work for the period and interval.
109 110 111 |
# File 'lib/artoo/robot.rb', line 109 def has_work?(period, interval) current_instance.timers.find {|t| t.recurring == (period == :every) && t.interval == interval} end |
#inspect ⇒ String
Returns robot.
128 129 130 |
# File 'lib/artoo/robot.rb', line 128 def inspect "#<Robot #{object_id}>" end |
#pause_work ⇒ Object
pause the work
69 70 71 72 |
# File 'lib/artoo/robot.rb', line 69 def pause_work Logger.info "Pausing work..." current_instance.timers.pause end |
#safe_name ⇒ String
Returns Name without spaces and downcased.
46 47 48 |
# File 'lib/artoo/robot.rb', line 46 def safe_name name.gsub(' ', '_').downcase end |
#to_hash ⇒ Hash
Returns robot.
114 115 116 117 118 119 120 |
# File 'lib/artoo/robot.rb', line 114 def to_hash { :name => name, :connections => connections.each_value.collect {|c|c.to_hash}, :devices => devices.each_value.collect {|d|d.to_hash} } end |
#work ⇒ Object
start doing the work
61 62 63 64 65 66 |
# File 'lib/artoo/robot.rb', line 61 def work Logger.info "Starting work..." execute_startup(connections) {|c| c.future.connect} execute_startup(devices) {|d| d.future.start_device} execute_working_code end |
#working_code ⇒ Proc
Returns current working code.
102 103 104 |
# File 'lib/artoo/robot.rb', line 102 def working_code current_class.working_code ||= proc {puts "No work defined."} end |