Class: OpenLighting::DmxDevice
- Inherits:
-
Object
- Object
- OpenLighting::DmxDevice
- Defined in:
- lib/open_lighting/dmx_device.rb
Overview
A DmxDevice represents a single controllable piece of physical hardware that can be controlled via DMX signals.
DmxDevice can be subclassed with sensible defaults for various pieces of hardware.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
Returns the value of attribute capabilities.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#current_values ⇒ Object
Returns the value of attribute current_values.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#points ⇒ Object
Returns the value of attribute points.
-
#start_address ⇒ Object
Returns the value of attribute start_address.
Instance Method Summary collapse
- #buffer(opt) ⇒ Object
-
#initialize(options = {}) ⇒ DmxDevice
constructor
A new instance of DmxDevice.
- #method_missing(meth, *args, &block) ⇒ Object
- #point(key) ⇒ Object
- #set(options) ⇒ Object
- #to_dmx ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DmxDevice
Returns a new instance of DmxDevice.
10 11 12 13 14 15 16 |
# File 'lib/open_lighting/dmx_device.rb', line 10 def initialize( = {}) self.start_address = [:start_address] self.capabilities = ([:capabilities] || []).map{|i| i.to_sym} self.defaults = [:defaults] || {} self.current_values = capabilities.map{|c| defaults[c] || 0 } self.points = [:points] || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/open_lighting/dmx_device.rb', line 49 def method_missing(meth, *args, &block) if points[meth] buffer points[meth] elsif capabilities.include? meth buffer meth => args.first else super # You *must* call super if you don't handle the # method, otherwise you'll mess up Ruby's method # lookup. end end |
Instance Attribute Details
#capabilities ⇒ Object
Returns the value of attribute capabilities.
9 10 11 |
# File 'lib/open_lighting/dmx_device.rb', line 9 def capabilities @capabilities end |
#controller ⇒ Object
Returns the value of attribute controller.
9 10 11 |
# File 'lib/open_lighting/dmx_device.rb', line 9 def controller @controller end |
#current_values ⇒ Object
Returns the value of attribute current_values.
9 10 11 |
# File 'lib/open_lighting/dmx_device.rb', line 9 def current_values @current_values end |
#defaults ⇒ Object
Returns the value of attribute defaults.
9 10 11 |
# File 'lib/open_lighting/dmx_device.rb', line 9 def defaults @defaults end |
#points ⇒ Object
Returns the value of attribute points.
9 10 11 |
# File 'lib/open_lighting/dmx_device.rb', line 9 def points @points end |
#start_address ⇒ Object
Returns the value of attribute start_address.
9 10 11 |
# File 'lib/open_lighting/dmx_device.rb', line 9 def start_address @start_address end |
Instance Method Details
#buffer(opt) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/open_lighting/dmx_device.rb', line 23 def buffer(opt) = opt.dup if opt return if .nil? if pt = .delete(:point) buffer points[pt] end capabilities.each_with_index do |c, i| unless [c].nil? current_values[i] = .delete(c) end end end |
#point(key) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/open_lighting/dmx_device.rb', line 38 def point(key) # d { key } # d { self.points } self.points[key] end |
#set(options) ⇒ Object
18 19 20 21 |
# File 'lib/open_lighting/dmx_device.rb', line 18 def set() warn "[DEPRECATION] `set` is deprecated. Use `buffer` instead." buffer() end |
#to_dmx ⇒ Object
45 46 47 |
# File 'lib/open_lighting/dmx_device.rb', line 45 def to_dmx current_values.join "," end |