Module: Linecounter::BranchAnalyzer
- Defined in:
- lib/linecounter/branch_analyzer.rb
Defined Under Namespace
Classes: CountingVisitor
Constant Summary collapse
- BRANCH_TOKENS =
Buckets of control-flow constructs, in display order. Counted from the parsed AST, so keywords inside strings and comments are never counted.
[ [:if, "if condition"], [:elsif, "elsif branch"], [:unless, "unless condition"], [:case, "case expression"], [:when, "when branch"], [:while, "while loop"], [:until, "until loop"], [:rescue, "rescue handler"], [:ensure, "ensure block"], [:begin, "begin block"], [:and, "logical AND (&& / and)"], [:or, "logical OR (|| / or)"], [:ternary, "ternary operator (?:)"], [:return, "return statement"] ].freeze
Class Method Summary collapse
Class Method Details
.breakdown(content) ⇒ Object
112 113 114 115 116 |
# File 'lib/linecounter/branch_analyzer.rb', line 112 def breakdown(content) visitor = CountingVisitor.new Prism.parse(content).value.accept(visitor) BRANCH_TOKENS.each_with_object({}) { |(name, _label), acc| acc[name] = visitor.counts[name] } end |