class Pragmater::Parsers::File
Parses a file into pragma comment and body lines.
Attributes
comments[R]
pattern[R]
processor[R]
Public Class Methods
new(pattern: Formatters::Main::PATTERN, comments: Comments, processor: Processors::Handler.new)
click to toggle source
# File lib/pragmater/parsers/file.rb, line 7 def initialize pattern: Formatters::Main::PATTERN, comments: Comments, processor: Processors::Handler.new @pattern = pattern @comments = comments @processor = processor end
Public Instance Methods
call(path, new_comments, action: path.each_line .partition { |line| line.match? pattern })
click to toggle source
# File lib/pragmater/parsers/file.rb, line 15 def call path, new_comments, action: path.each_line .partition { |line| line.match? pattern } .then do |old_comments, body| processor.call action, wrap_in_new_line(old_comments, new_comments, action), body end end
Private Instance Methods
wrap_in_new_line(old_comments, new_comments, action)
click to toggle source
# File lib/pragmater/parsers/file.rb, line 27 def wrap_in_new_line old_comments, new_comments, action comments.new(old_comments, new_comments).public_send(action).map { |line| "#{line}\n" } end