Class: JsonInference::Node
Instance Method Summary
collapse
Methods inherited from BaseNode
#<<, #each_sub_node, #indent, #indent_level
Constructor Details
#initialize(name = nil, parent = nil) ⇒ Node
Returns a new instance of Node.
3
4
5
6
|
# File 'lib/json-inference/node.rb', line 3
def initialize(name = nil, parent = nil)
super()
@name, @parent = name, parent
end
|
Instance Method Details
#selector ⇒ Object
8
9
10
|
# File 'lib/json-inference/node.rb', line 8
def selector
"#{@parent.selector} > .#{@name}"
end
|
#selector_line(documents_count) ⇒ Object
12
13
14
|
# File 'lib/json-inference/node.rb', line 12
def selector_line(documents_count)
"#{indent}#{selector}: #{@values.size}/#{documents_count} (#{JsonInference.percent_string(@values.size, documents_count)})\n"
end
|
#to_s(documents_count) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/json-inference/node.rb', line 16
def to_s(documents_count)
str = ""
str << selector_line(documents_count)
str << @values.to_s(indent)
each_sub_node do |sub_node|
str << sub_node.to_s(documents_count)
end
str
end
|