module Elparser
Constants
- VERSION
Public Class Methods
encode(obj)
click to toggle source
Translate a ruby object to s-expression string.
# File lib/elparser.rb, line 316 def self.encode(obj) return _encode(obj).to_s end
encode_multi(objs, sep = "\n")
click to toggle source
Translate many ruby objects to s-expression string. The result s-exps are concatenated into one string.
# File lib/elparser.rb, line 322 def self.encode_multi(objs, sep = "\n") return objs.map {|obj| _encode(obj).to_s }.join(sep) end
Private Class Methods
_encode(arg)
click to toggle source
# File lib/elparser.rb, line 339 def self._encode(arg) return "nil" if arg.nil? c = arg.class if c == Fixnum then return SExpNumber.new :INTEGER, arg.to_s elsif c == Float then return SExpNumber.new :FLOAT, arg.to_s elsif c == String then return SExpString.new arg elsif c == Symbol then return SExpSymbol.new arg.to_s elsif c == Array then return _encode_array(arg) elsif c == Hash then return _encode_hash(arg) elsif c == TrueClass then return SExpSymbol.new "t" elsif c == FalseClass then return SExpNil.new end raise EncodingError.new("Can't encode object : #{arg}", arg) end
_encode_array(arg)
click to toggle source
# File lib/elparser.rb, line 362 def self._encode_array(arg) return SExpNil.new if arg.nil? || arg.size == 0 return SExpList.new arg.map{|i| _encode(i)} end
_encode_hash(arg)
click to toggle source
# File lib/elparser.rb, line 367 def self._encode_hash(arg) return SExpNil.new if arg.nil? || arg.size == 0 return SExpList.new arg.map{|k,v| SExpCons.new(_encode(k),_encode(v))} end