Class: Pragmater::Parsers::File
- Inherits:
-
Object
- Object
- Pragmater::Parsers::File
- Defined in:
- lib/pragmater/parsers/file.rb
Overview
Parses a file into pragma comment and body lines.
Instance Method Summary collapse
- #call(path, new_comments, action:) ⇒ Object
-
#initialize(pattern: Formatters::Main::PATTERN, comments: Comments, processor: Processors::Handler.new) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(pattern: Formatters::Main::PATTERN, comments: Comments, processor: Processors::Handler.new) ⇒ File
Returns a new instance of File.
7 8 9 10 11 12 13 |
# 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 |
Instance Method Details
#call(path, new_comments, action:) ⇒ Object
15 16 17 18 19 20 21 |
# 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 |