summaryrefslogtreecommitdiff
path: root/lib/yaml/yamlnode.rb
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-09 21:25:50 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-09 21:25:50 +0000
commit55f4dc4c9a5345c28d0da750d1ee00fbb0870885 (patch)
tree904359659b75882365348decb2ca0789ca1ac803 /lib/yaml/yamlnode.rb
parent605adb86e2c2889c13e07cadf328f8032eebae7c (diff)
Initial checkin of YAML substances.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml/yamlnode.rb')
-rw-r--r--lib/yaml/yamlnode.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/yaml/yamlnode.rb b/lib/yaml/yamlnode.rb
new file mode 100644
index 0000000000..e36a18e694
--- /dev/null
+++ b/lib/yaml/yamlnode.rb
@@ -0,0 +1,54 @@
+#
+# YAML::YamlNode class
+#
+require 'yaml/basenode'
+
+module YAML
+
+ #
+ # YAML Generic Model container
+ #
+ class YamlNode
+ include BaseNode
+ attr_accessor :kind, :type_id, :value, :anchor
+ def initialize( t, v )
+ @type_id = t
+ if Hash === v
+ @kind = 'map'
+ @value = {}
+ v.each { |k,v|
+ @value[ k.transform ] = [ k, v ]
+ }
+ elsif Array === v
+ @kind = 'seq'
+ @value = v
+ elsif String === v
+ @kind = 'scalar'
+ @value = v
+ end
+ end
+
+ #
+ # Transform this node fully into a native type
+ #
+ def transform
+ t = nil
+ if @value.is_a? Hash
+ t = {}
+ @value.each { |k,v|
+ t[ k ] = v[1].transform
+ }
+ elsif @value.is_a? Array
+ t = []
+ @value.each { |v|
+ t.push v.transform
+ }
+ else
+ t = @value
+ end
+ YAML.transfer_method( @type_id, t )
+ end
+
+ end
+
+end