Class: JsonInference::NthChildNode
Instance Method Summary
collapse
Methods inherited from BaseNode
#<<, #each_sub_node, #indent, #indent_level, #total_count
Constructor Details
87
88
89
90
|
# File 'lib/json-inference.rb', line 87
def initialize(parent)
super()
@parent = parent
end
|
Instance Method Details
#selector ⇒ Object
92
93
94
|
# File 'lib/json-inference.rb', line 92
def selector
"#{@parent.selector}:nth-child()"
end
|
#selector_line(documents_count) ⇒ Object
96
97
98
|
# File 'lib/json-inference.rb', line 96
def selector_line(documents_count)
"#{indent}#{selector}: #{total_count} child#{'ren' unless total_count == 1}\n"
end
|
#to_s(documents_count) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/json-inference.rb', line 100
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(total_count)
end
str
end
|