Class: JsonInference::Node

Inherits:
BaseNode show all
Defined in:
lib/json-inference.rb

Instance Method Summary collapse

Methods inherited from BaseNode

#<<, #each_sub_node, #indent, #indent_level, #total_count

Constructor Details

#initialize(name = nil, parent = nil) ⇒ Node

Returns a new instance of Node.



60
61
62
63
# File 'lib/json-inference.rb', line 60

def initialize(name = nil, parent = nil)
  super()
  @name, @parent = name, parent
end

Instance Method Details

#selectorObject



65
66
67
# File 'lib/json-inference.rb', line 65

def selector
  "#{@parent.selector} > .#{@name}"
end

#selector_line(documents_count) ⇒ Object



69
70
71
# File 'lib/json-inference.rb', line 69

def selector_line(documents_count)
  "#{indent}#{selector}: #{total_count}/#{documents_count} (#{(total_count.to_f / documents_count * 100).round}%)\n"
end

#to_s(documents_count) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/json-inference.rb', line 73

def to_s(documents_count)
  str = ""
  str << selector_line(documents_count)
  @value_classes.each do |klass, count|
    str << "  #{indent}#{klass}: #{(count / total_count.to_f * 100).round}%\n"
  end
  each_sub_node do |sub_node|
    str << sub_node.to_s(documents_count)
  end
  str
end