class Minireq::Gitbook::Node

Tree node
Example:
    include Md2gitbook
    r = Node.new("title")
    r << Node.new("subtitle 1")
    r << Node.new("subtitle 2")

end

Attributes

body[R]
header[R]
items[R]
parent[RW]

Public Class Methods

new(header, body = '') click to toggle source
# File lib/minireq/gitbook/node.rb, line 27
def initialize(header, body = '')
  @header = header
  @body   = body
  @parent = nil
  @items  = []
end

Public Instance Methods

<<(obj) click to toggle source
# File lib/minireq/gitbook/node.rb, line 34
def <<(obj)
  @items << obj
  obj.parent = self if obj.is_a? Node
end
find(header) click to toggle source
# File lib/minireq/gitbook/node.rb, line 56
def find(header)
  visit{|n| return n if n.header.eql?(header)}
  return nil
end
level() click to toggle source
# File lib/minireq/gitbook/node.rb, line 39
def level
  l = 0
  # return 0 unless @parent
  p = @parent
  while p
    l += 1
    p = p.parent
  end
  l
end
to_s() click to toggle source
# File lib/minireq/gitbook/node.rb, line 61
def to_s
  @header
end
visit() { |self| ... } click to toggle source
# File lib/minireq/gitbook/node.rb, line 50
def visit(&block)
  return unless block_given?
  yield(self)
  each {|n| n.visit(&block)}
end