diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-28 11:54:39 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-28 11:54:39 -0700 |
commit | f4e5e8205ee3b63403a6b6695746046cd663d6d8 (patch) | |
tree | 6fc5088df62f3a900e231778bee7d0b8b1fa3e0d | |
parent | 483d0d30bf783e04dfdb458b65219281dda76cff (diff) | |
download | psych-f4e5e8205ee3b63403a6b6695746046cd663d6d8.zip |
mappings convert
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 6 | ||||
-rw-r--r-- | test/visitors/test_to_ruby.rb | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 57db346..b82fc3c 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -8,7 +8,11 @@ module Psych end visitor_for(Nodes::Sequence) do |o| - o.children.map { |o| o.accept self } + o.children.map { |c| c.accept self } + end + + visitor_for(Nodes::Mapping) do |o| + Hash[*o.children.map { |c| c.accept self }] end end end diff --git a/test/visitors/test_to_ruby.rb b/test/visitors/test_to_ruby.rb index f514178..db748ca 100644 --- a/test/visitors/test_to_ruby.rb +++ b/test/visitors/test_to_ruby.rb @@ -21,6 +21,13 @@ module Psych assert_equal %w{ foo bar }, seq.to_ruby end + + def test_mapping + mapping = Nodes::Mapping.new + mapping.children << Nodes::Scalar.new('foo') + mapping.children << Nodes::Scalar.new('bar') + assert_equal({'foo' => 'bar'}, mapping.to_ruby) + end end end end |