Class: Shiolink
- Inherits:
-
Object
- Object
- Shiolink
- Defined in:
- lib/shiolink.rb
Overview
SHIOLINK interface
Instance Method Summary (collapse)
-
- (String) add_line(line)
add line.
-
- (Shiolink) initialize(load, unload, request)
constructor
initialize with callbacks.
-
- (Object) start(input = $stdin, output = $stdout)
start watching IO.
Constructor Details
- (Shiolink) initialize(load, unload, request)
initialize with callbacks
7 8 9 10 11 12 |
# File 'lib/shiolink.rb', line 7 def initialize(load, unload, request) @load = load @unload = unload @request = request @session = nil end |
Instance Method Details
- (String) add_line(line)
add line
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/shiolink.rb', line 17 def add_line(line) unless @session case line[0 ... 3] when '*L:' path = line[3 ... line.size].chomp + line.match(/[\/\\]/).to_s @load.call(path) nil when '*S:' @session = '' line when '*U:' @unload.call nil end else @session += line if line.chomp.size != 0 nil else response = @request.call(@session) @session = nil response end end end |
- (Object) start(input = $stdin, output = $stdout)
start watching IO
46 47 48 49 50 51 52 53 |
# File 'lib/shiolink.rb', line 46 def start(input = $stdin, output = $stdout) input.each_line do |line| if response = add_line(line) output.print(response) #output.flush end end end |