class NestedStringParser::Node

Attributes

children[RW]
nesting[RW]
parent[RW]
value[RW]

Public Class Methods

new(s=nil ;) click to toggle source
# File lib/nested_string_parser.rb, line 7
def initialize     s=nil ; @nesting, @value, @children = (s ? s.gsub(/^( *)[^ ].*/, '\1').length : -1), (s && s.strip), [] ; end

Public Instance Methods

accept(str=nil, *ss ;) click to toggle source
# File lib/nested_string_parser.rb, line 12
def accept str=nil, *ss ; nb?(str) ? add_child?(Node.new(str)).accept(*ss) : (ss.size > 0 ? self.accept(*ss) : self)       ; end
add_child(child ;) click to toggle source
# File lib/nested_string_parser.rb, line 9
def add_child      child ; @children << child ; child.parent = self ; child                                                ; end
add_child?(child ;) click to toggle source
# File lib/nested_string_parser.rb, line 8
def add_child?     child ; (child.nesting > self.nesting) ? add_child(child) : parent.add_child?(child)                    ; end
find(name ;) click to toggle source
# File lib/nested_string_parser.rb, line 15
def find            name ; children.detect { |k| k.value == name }                                                         ; end
format(indent ;) click to toggle source
# File lib/nested_string_parser.rb, line 14
def format        indent ; %[#{indent}#{value}\n#{children.map { |c| c.format "#{indent}  " }.join}]                       ; end
nb?(str ;) click to toggle source
# File lib/nested_string_parser.rb, line 11
def nb?              str ; str && str.strip != ""                                                                          ; end
nest_child(child ;) click to toggle source
# File lib/nested_string_parser.rb, line 10
def nest_child     child ; add_child(child).tap { |c| c.nesting = nesting + 1 }                                            ; end
root() click to toggle source
# File lib/nested_string_parser.rb, line 13
def root                 ; parent ? parent.root : self                                                                     ; end