Class: Rails::SourceAnnotationExtractor::PatternExtractor

Inherits:
Struct
  • Object
show all
Defined in:
lib/rails/source_annotation_extractor.rb

Overview

Wraps a regular expression that will iterate through a file’s lines and test each one for the given pattern.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#patternObject

Returns the value of attribute pattern

Returns:

  • (Object)

    the current value of pattern



42
43
44
# File 'lib/rails/source_annotation_extractor.rb', line 42

def pattern
  @pattern
end

Instance Method Details

#annotations(file) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/rails/source_annotation_extractor.rb', line 43

def annotations(file)
  lineno = 0

  File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
    lineno += 1
    next list unless line =~ pattern
    list << Annotation.new(lineno, $1, $2)
  end
end