Class: Taopaipai::Pin
- Inherits:
-
Object
- Object
- Taopaipai::Pin
- Defined in:
- lib/taopaipai/pin.rb
Instance Method Summary collapse
- #apply! ⇒ Object
- #direction(direction) ⇒ Object
- #export ⇒ Object
-
#initialize(io, options = {}) ⇒ Pin
constructor
A new instance of Pin.
- #unexport ⇒ Object
- #value(value = nil) ⇒ Object
Constructor Details
#initialize(io, options = {}) ⇒ Pin
Returns a new instance of Pin.
4 5 6 7 |
# File 'lib/taopaipai/pin.rb', line 4 def initialize(io, ={}) @io = io @state = PinState.new() end |
Instance Method Details
#apply! ⇒ Object
9 10 11 |
# File 'lib/taopaipai/pin.rb', line 9 def apply! export.apply_direction.apply_value end |
#direction(direction) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/taopaipai/pin.rb', line 13 def direction(direction) @state.changing :direction, direction do apply_direction end self end |
#export ⇒ Object
36 37 38 39 |
# File 'lib/taopaipai/pin.rb', line 36 def export @io.export(@state.number) if @state.export! self end |
#unexport ⇒ Object
31 32 33 34 |
# File 'lib/taopaipai/pin.rb', line 31 def unexport @io.unexport(@state.number) if @state.unexport! self end |
#value(value = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/taopaipai/pin.rb', line 20 def value(value = nil) if @state.out? @state.changing :value, value do apply_value end self else @state.value = @io.read(@state.number) end end |