Class: ErlangConfig::ErlTerm
- Inherits:
-
Object
- Object
- ErlangConfig::ErlTerm
- Defined in:
- lib/erlang_config/erlterm.rb
Instance Attribute Summary collapse
-
#str ⇒ Object
Returns the value of attribute str.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(str) ⇒ ErlTerm
constructor
A new instance of ErlTerm.
Constructor Details
#initialize(str) ⇒ ErlTerm
Returns a new instance of ErlTerm.
4 5 6 |
# File 'lib/erlang_config/erlterm.rb', line 4 def initialize(str) @str = str end |
Instance Attribute Details
#str ⇒ Object
Returns the value of attribute str.
3 4 5 |
# File 'lib/erlang_config/erlterm.rb', line 3 def str @str end |
Class Method Details
.decode(str) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/erlang_config/erlterm.rb', line 8 def self.decode(str) str.strip! term_open_str = str[/^(\[|\{|\"|\'|<<|#Ref|<)/,1] if term_open_str.nil? # integer,float, or, atom matches = /^(([-0-9\.]+)|([a-z][a-z0-9_]*))/.match(str) term = case when (matches[2] && str[/\./]) then str.to_f when matches[2] then str.to_i when matches[3] then str.to_sym end else term_close_str = ERL_CLOSE_STRS[term_open_str] re_ends_with_close_str = Regexp.new(Regexp.escape("#{term_close_str}")+"$") raise "Parse error, Invalid erlang term #{str}" unless re_ends_with_close_str.match(str) term = case term_open_str when '[' then ErlList.new(str) when '{' then ErlTuple.new(str) when '"' then ErlString.new(str) when "'" then ErlAtom.new(str) when "<<" then ErlBinary.new(str) when "#Ref" then ErlRef.new(str) when "<" then ErlPid.new(str) else raise "Parse error with #{term_open_str}" end end term end |