Class: RegexFileProcesser

Inherits:
FileProcesserInterface show all
Defined in:
lib/file_processer.rb

Instance Method Summary collapse

Constructor Details

#initialize(regex, genLineFunc) ⇒ RegexFileProcesser

Returns a new instance of RegexFileProcesser.



34
35
36
37
# File 'lib/file_processer.rb', line 34

def initialize(regex, genLineFunc)
    @regex = regex
    @genLineFunc = genLineFunc
end

Instance Method Details

#process(filePath) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/file_processer.rb', line 39

def process(filePath)
    buffer = ""
    IO.foreach(filePath) { |line|
        current_number_regex = line =~ @regex
        if current_number_regex
            regexCatchedValue = $~
            buffer += line.gsub(@regex, @genLineFunc.call(regexCatchedValue))
        else
            buffer += line
        end
    }
    YDFileUtils.writeFile(filePath, buffer)
end