Class: ErlangAdapter
- Inherits:
-
Object
- Object
- ErlangAdapter
- Defined in:
- lib/erlang_adapter.rb
Overview
Erlang specific commands and evaluator
Instance Method Summary collapse
-
#eval(command) ⇒ Object
whitespace to differentiate between floats and EOL.
-
#initialize(host = "localhost", port = 9900) ⇒ ErlangAdapter
constructor
Erlang host server name (the default is “localhost”) [Port] Erlang server port number (the default is “9900”).
-
#is_error(str) ⇒ Object
Quick boolean to decide whether the data returned from Erlang was an error.
-
#make_command(erlang_mod, erlang_func, args) ⇒ Object
Create an Erlang command from the ruby-style syntax [erlang_mod] Erlang module [erlang_func] Erlang function [args] Arguments to pass to function.
-
#to_erlang_args(args) ⇒ Object
Translate a Ruby array to Erlang elements.
-
#to_erlang_literal(x) ⇒ Object
isn’t a basic argument.
Constructor Details
#initialize(host = "localhost", port = 9900) ⇒ ErlangAdapter
Erlang host server name (the default is “localhost”)
- Port
-
Erlang server port number (the default is “9900”)
28 29 30 |
# File 'lib/erlang_adapter.rb', line 28 def initialize(host="localhost", port=9900) @host, @port = host, port end |
Instance Method Details
#eval(command) ⇒ Object
whitespace to differentiate between floats and EOL.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/erlang_adapter.rb', line 34 def eval(command) socket = TCPSocket.new(@host, @port) # There has to be a trailing space at the end of a command for erl_scan:tokens # to process the string. command << '.' if command.scan(/\.\w*/).empty? command << " " socket.write(command) socket.read # ...? end |
#is_error(str) ⇒ Object
Quick boolean to decide whether the data returned from Erlang was an error.
79 80 81 |
# File 'lib/erlang_adapter.rb', line 79 def is_error(str) str[0..5] == "Error:" end |
#make_command(erlang_mod, erlang_func, args) ⇒ Object
Create an Erlang command from the ruby-style syntax
- erlang_mod
-
Erlang module
- erlang_func
-
Erlang function
- args
-
Arguments to pass to function. Should be in a Ruby array.
52 53 54 |
# File 'lib/erlang_adapter.rb', line 52 def make_command(erlang_mod, erlang_func, args) "#{erlang_mod}:#{erlang_func}(#{to_erlang_args(args)})." end |
#to_erlang_args(args) ⇒ Object
Translate a Ruby array to Erlang elements.
57 58 59 |
# File 'lib/erlang_adapter.rb', line 57 def to_erlang_args(args) args.map{ |x| to_erlang_literal x }.join(',') end |
#to_erlang_literal(x) ⇒ Object
isn’t a basic argument.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/erlang_adapter.rb', line 64 def to_erlang_literal(x) if x.kind_of?(String) then "\"#{x}\"" elsif x.kind_of?(Integer) then x elsif x.kind_of?(Float) then x elsif x.kind_of?(Array) then "[#{x.map{|y| to_erlang_literal(y)}.join(',')}]" else raise "Can't use \"#{x.type} Object\" in arguments." end end |