Sha256: 5219f7047aaf3dfed7710e4d2ce0fad37175c6da38e9fe491a2935414b06f75f

Contents?: true

Size: 822 Bytes

Versions: 2

Compression:

Stored size: 822 Bytes

Contents

module Rfactor

  class LineFinder
    
    def initialize(ast)
      @ast = ast
    end
    
    def method_lines(line_in_code)
      processor = MethodLineFinderProcessor.new(line_in_code)
      processor.process(@ast)
      Range.new(processor.method_line, processor.last_method_line)
    end
  end
  
  class MethodLineFinderProcessor < ::SexpProcessor
    attr_reader :method_line
    attr_reader :last_method_line
    
    def initialize(line)
      super()
      self.strict = false
      self.require_empty = false
      @line = line
      @method_line = 0
      @last_method_line = 0
    end
    
    def process_defn(exp)
      current = exp.line
      if current > @method_line && current < @line
        @method_line = current
        @last_method_line = exp.endline
      end
      exp
    end    
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fabiokung-rfactor-0.0.1 lib/rfactor/line_finder.rb
fabiokung-rfactor-0.0.2 lib/rfactor/line_finder.rb