class Modloc::Source
A Modloc
source string
Attributes
ext[R]
path[R]
Public Class Methods
new(file)
click to toggle source
Creates a new Modloc
source object @param file [String]
Calls superclass method
# File lib/modloc/source.rb, line 10 def initialize(file) @ext = File.extname(file) @path = file super File.read file rescue Errno::ENOENT super '' end
Public Instance Methods
lines()
click to toggle source
Returns the sources lines as line objects @return [Array<Modloc::Source::Line>]
Calls superclass method
# File lib/modloc/source.rb, line 20 def lines super.map { |line| Line.new line } end
locate_all(pattern)
click to toggle source
Locate all the locations matching a given pattern @param pattern [Regexp] @return [Array]
# File lib/modloc/source.rb, line 27 def locate_all(pattern) [].tap do |locations| strip.lines.each_with_index.reduce('') do |contents, (line, index)| line_num = index + 1 contents << line if contents.match(/#{pattern.source}\n\z/) locations << [path, line_num] end contents end end end
strip()
click to toggle source
Return the source without comments or whitespace for each line @return [Modloc::Source]
# File lib/modloc/source.rb, line 42 def strip dup.replace lines.map(&:strip).join end