Class: Spoom::Coverage::D3::CircleMap::Sigils
Instance Attribute Summary
Attributes inherited from Base
#id
Instance Method Summary
collapse
header_script, header_style, #script
Methods inherited from Base
header_script, header_style, #html, #script, #tooltip
Constructor Details
#initialize(id, sigils_tree) ⇒ Sigils
150
151
152
153
154
155
|
# File 'lib/spoom/coverage/d3/circle_map.rb', line 150
def initialize(id, sigils_tree)
@scores = T.let({}, T::Hash[FileTree::Node, Float])
@strictnesses = T.let({}, T::Hash[FileTree::Node, T.nilable(String)])
@sigils_tree = sigils_tree
super(id, sigils_tree.roots.map { |r| tree_node_to_json(r) })
end
|
Instance Method Details
#tree_node_score(node) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/spoom/coverage/d3/circle_map.rb', line 178
def tree_node_score(node)
unless @scores.key?(node)
if node.name =~ /\.rbi?$/
case tree_node_strictness(node)
when "true", "strict", "strong"
@scores[node] = 1.0
end
elsif !node.children.empty?
@scores[node] = node.children.values.sum { |n| tree_node_score(n) } / node.children.size.to_f
end
end
@scores[node] || 0.0
end
|
#tree_node_strictness(node) ⇒ Object
170
171
172
173
174
175
|
# File 'lib/spoom/coverage/d3/circle_map.rb', line 170
def tree_node_strictness(node)
prefix = @sigils_tree.strip_prefix
path = node.path
path = "#{prefix}/#{path}" if prefix
@strictnesses[node] ||= Spoom::Sorbet::Sigils.file_strictness(path)
end
|
#tree_node_to_json(node) ⇒ Object
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/spoom/coverage/d3/circle_map.rb', line 158
def tree_node_to_json(node)
if node.children.empty?
return { name: node.name, strictness: tree_node_strictness(node) }
end
{
name: node.name,
children: node.children.values.map { |n| tree_node_to_json(n) },
score: tree_node_score(node),
}
end
|