class RamlParser::YamlNode
Attributes
key[R]
marks[R]
parent[R]
value[R]
Public Class Methods
new(parent, key, value)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 5 def initialize(parent, key, value) @parent = parent @key = key @value = value @marks = {} end
Public Instance Methods
array(index)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 51 def array(index) new_node = YamlNode.new(self, "[#{index}]", @value[index]) new_node.mark(:used) new_node end
array_values(&code)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 57 def array_values(&code) (@value || []).each_with_index.map { |_,i| code.call(array(i)) } end
arrayhash(index)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 71 def arrayhash(index) new_node = array(index) new_node.mark(:used) new_node2 = new_node.hash(new_node.value.first[0]) new_node2.mark(:used) new_node2 end
arrayhash_values(&code)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 79 def arrayhash_values(&code) Hash[(@value || []).each_with_index.map { |_,i| node = arrayhash(i) [node.key, code.call(node)] }] end
hash(key)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 61 def hash(key) new_node = YamlNode.new(self, key, @value[key]) new_node.mark(:used) new_node end
hash_values(&code)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 67 def hash_values(&code) Hash[(@value || {}).map { |k,v| [k, code.call(hash(k))] }] end
mark(what, p = path)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 28 def mark(what, p = path) if parent.nil? @marks[p] = what else @parent.mark(what, p) end self end
mark_all(what)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 37 def mark_all(what) mark(what) if @value.is_a? Hash hash_values { |n| n.mark_all(what) } elsif @value.is_a? Array array_values { |n| n.mark_all(what) } end self end
or_default(default)
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 47 def or_default(default) @value != nil ? self : YamlNode.new(@parent, @key, default) end
path()
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 20 def path if @parent != nil "#{@parent.path}.#{@key}" else @key end end
root()
click to toggle source
# File lib/raml_parser/yaml_helper.rb, line 12 def root if @parent != nil @parent.root else self end end