class NicInfo::DataTree
Public Class Methods
new()
click to toggle source
# File lib/nicinfo/data_tree.rb, line 61 def initialize @roots = [] end
Public Instance Methods
add_child(node)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 69 def add_child node add_root( node ) end
add_children_as_root(node)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 73 def add_children_as_root node node.children.each do |child| add_root( child ) end if node end
add_root(node)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 65 def add_root node @roots << node if node end
empty?()
click to toggle source
# File lib/nicinfo/data_tree.rb, line 83 def empty? @roots.empty? end
find_data(data_address)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 87 def find_data data_address node = find_node data_address return node.data if node return nil end
find_handle(data_address)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 93 def find_handle data_address node = find_node data_address return node.handle if node return nil end
find_node(data_address)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 105 def find_node data_address node = NicInfo::DataNode.new( "fakeroot" ) node.children=roots data_address.split( /\D/ ).each do |index_str| index = index_str.to_i - 1 node = node.children[ index ] if node end if node != nil return node end #else return nil end
find_rest_ref(data_address)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 99 def find_rest_ref data_address node = find_node data_address return node.rest_ref if node return nil end
roots()
click to toggle source
# File lib/nicinfo/data_tree.rb, line 79 def roots @roots end
to_extra_log(logger, annotate = false)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 131 def to_extra_log logger, annotate = false @logger = logger @data_amount = DataAmount::EXTRA_DATA to_log( annotate ) end
to_normal_log(logger, annotate = false)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 125 def to_normal_log logger, annotate = false @logger = logger @data_amount = DataAmount::NORMAL_DATA to_log( annotate ) end
to_terse_log(logger, annotate = false)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 119 def to_terse_log logger, annotate = false @logger = logger @data_amount = DataAmount::TERSE_DATA to_log( annotate ) end
Private Instance Methods
rprint( num, parent, node, prefix )
click to toggle source
# File lib/nicinfo/data_tree.rb, line 178 def rprint( num, parent, node, prefix ) if( num > 0 ) spacer = " " if node.alert num_str = format( " # ", num ) elsif node.has_meta_info num_str = format( " %d= ", num ) else num_str = format( " %d. ", num ) end num_str = num_str.rjust( 7, "-" ) child_num = 1 else spacer = " " num_str = "- " child_num = 0 end prefix = prefix.tr( "`", " ") + spacer + ( node == parent.children.last ? "`" : "|" ) @logger.log_tree_item( @data_amount, prefix + num_str + node.to_s, NicInfo::AttentionType::SUCCESS ) node.children.each do |child| rprint( child_num, node, child, prefix ) child_num += 1 if child_num > 0 end if node.children() != nil end
to_log(annotate)
click to toggle source
# File lib/nicinfo/data_tree.rb, line 139 def to_log annotate retval = false print_tree = false @roots.each do |root| print_tree = true unless root.children.empty? end num_count = 1 @logger.start_data_item if print_tree @logger.prose( @data_amount, "[ RESPONSE DATA ]", " ", NicInfo::AttentionType::SUCCESS ) @roots.each do |root| if annotate if root.alert s = format( " # %s", root.to_s ) elsif root.has_meta_info s = format( "%3d= %s", num_count, root.to_s ) else s = format( "%3d. %s", num_count, root.to_s ) end else s = root.to_s end retval = @logger.log_tree_item( @data_amount, s, NicInfo::AttentionType::SUCCESS ) if annotate prefix = " " child_num = 1 else prefix = "" child_num = 0 end root.children.each do |child| rprint( child_num, root, child, prefix ) child_num += 1 if child_num > 0 end if root.children() != nil num_count += 1 end if print_tree @logger.end_data_item if print_tree return retval end