From 16261f96b0d4640341cb5165f71af2567362e525 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 15 Aug 2014 17:14:49 +0300 Subject: [PATCH] adds simple hash and test --- lib/sof/all.rb | 1 + lib/sof/hash.rb | 13 +++++++++++++ test/sof.rb | 6 +++++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 lib/sof/hash.rb diff --git a/lib/sof/all.rb b/lib/sof/all.rb index 35a92570..cbdf2ffc 100644 --- a/lib/sof/all.rb +++ b/lib/sof/all.rb @@ -3,6 +3,7 @@ require_relative "members" require_relative "volotile" require_relative "writer" require_relative "array" +require_relative "hash" require_relative "occurence" Symbol.class_eval do diff --git a/lib/sof/hash.rb b/lib/sof/hash.rb new file mode 100644 index 00000000..b90d602b --- /dev/null +++ b/lib/sof/hash.rb @@ -0,0 +1,13 @@ +Hash.class_eval do + def to_sof(io , members , level) + each_with_index do |pair , i| + key , object = pair + io.write(" " * level) unless i == 0 + io.write "-" + members.output( io , key) + io.write( " " ) + members.output( io , object) + io.write("\n") + end + end +end diff --git a/test/sof.rb b/test/sof.rb index ffe8c052..d6cd1269 100644 --- a/test/sof.rb +++ b/test/sof.rb @@ -41,5 +41,9 @@ class BasicSof < MiniTest::Test out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]]) assert_equal "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}\n\n\n" , out end - + def test_simple_hash + out = Sof::Writer.write({ one: 1 , tru: true }) + puts out + assert_equal "-:one 1\n-:tru true\n" , out + end end \ No newline at end of file