Class: NodeTypeCounter
- Inherits:
-
Parser::Rewriter
- Object
- Parser::Rewriter
- NodeTypeCounter
- Defined in:
- lib/zombie_killer/node_type_counter.rb
Instance Attribute Summary collapse
-
#node_types ⇒ Object
readonly
Returns the value of attribute node_types.
Instance Method Summary collapse
-
#initialize(filename) ⇒ NodeTypeCounter
constructor
A new instance of NodeTypeCounter.
- #print(io) ⇒ Object
- #process(node) ⇒ Object
Constructor Details
#initialize(filename) ⇒ NodeTypeCounter
Returns a new instance of NodeTypeCounter.
8 9 10 11 |
# File 'lib/zombie_killer/node_type_counter.rb', line 8 def initialize(filename) @node_types = CodeHistogram.new @filename = filename end |
Instance Attribute Details
#node_types ⇒ Object (readonly)
Returns the value of attribute node_types.
6 7 8 |
# File 'lib/zombie_killer/node_type_counter.rb', line 6 def node_types @node_types end |
Instance Method Details
#print(io) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/zombie_killer/node_type_counter.rb', line 19 def print(io) parser = Parser::CurrentRuby.new buffer = Parser::Source::Buffer.new(@filename) buffer.read ast = parser.parse(buffer) process(ast) @node_types.print_by_frequency(io) end |
#process(node) ⇒ Object
13 14 15 16 17 |
# File 'lib/zombie_killer/node_type_counter.rb', line 13 def process(node) return if node.nil? @node_types.increment(node.type) super end |