class Taopaipai::Pin

Public Class Methods

new(io, options={}) click to toggle source
# File lib/taopaipai/pin.rb, line 4
def initialize(io, options={})
  @io = io
  @state = PinState.new(options)
end

Public Instance Methods

apply!() click to toggle source
# File lib/taopaipai/pin.rb, line 9
def apply!
  export.apply_direction.apply_value
end
direction(direction) click to toggle source
# File lib/taopaipai/pin.rb, line 13
def direction(direction)
  @state.changing :direction, direction do
    apply_direction
  end
  self
end
export() click to toggle source
# File lib/taopaipai/pin.rb, line 36
def export
  @io.export(@state.number) if @state.export!
  self
end
unexport() click to toggle source
# File lib/taopaipai/pin.rb, line 31
def unexport
  @io.unexport(@state.number) if @state.unexport!
  self
end
value(value = nil) click to toggle source
# 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

Protected Instance Methods

apply_direction() click to toggle source
# File lib/taopaipai/pin.rb, line 43
def apply_direction
  @io.direction(@state.number, @state.direction)
  self
end
apply_value() click to toggle source
# File lib/taopaipai/pin.rb, line 48
def apply_value
  if @state.out? && @state.value
    @io.write(@state.number, @state.value)
  end
  self
end