lib/bert/encoder.rb in bert-1.0.0 vs lib/bert/encoder.rb in bert-1.1.0

- old
+ new

@@ -4,41 +4,40 @@ # +ruby+ is the Ruby object # # Returns a BERT def self.encode(ruby) complex_ruby = convert(ruby) - Erlectricity::Encoder.encode(complex_ruby) + Encode.encode(complex_ruby) end - # Convert Ruby types into corresponding Erlectricity representation - # of BERT complex types. + # Convert complex Ruby form in simple Ruby form. # +item+ is the Ruby object to convert # # Returns the converted Ruby object def self.convert(item) case item when Hash - pairs = Erl::List[] - item.each_pair { |k, v| pairs << [convert(k), convert(v)] } - [:bert, :dict, pairs] + pairs = [] + item.each_pair { |k, v| pairs << t[convert(k), convert(v)] } + t[:bert, :dict, pairs] when Tuple - item.map { |x| convert(x) } + Tuple.new(item.map { |x| convert(x) }) when Array - Erl::List.new(item.map { |x| convert(x) }) + item.map { |x| convert(x) } when nil - [:bert, :nil] + t[:bert, :nil] when TrueClass - [:bert, :true] + t[:bert, :true] when FalseClass - [:bert, :false] + t[:bert, :false] when Time - [:bert, :time, item.to_i / 1_000_000, item.to_i % 1_000_000, item.usec] + t[:bert, :time, item.to_i / 1_000_000, item.to_i % 1_000_000, item.usec] when Regexp - options = Erl::List[] + options = [] options << :caseless if item.options & Regexp::IGNORECASE > 0 options << :extended if item.options & Regexp::EXTENDED > 0 options << :multiline if item.options & Regexp::MULTILINE > 0 - [:bert, :regex, item.source, options] + t[:bert, :regex, item.source, options] else item end end end \ No newline at end of file