Class: Adjutant::FileParser
- Inherits:
-
Object
- Object
- Adjutant::FileParser
- Defined in:
- lib/adjutant/file_parser.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
Instance Method Summary collapse
- #detect_comments ⇒ Object
-
#initialize(file) ⇒ FileParser
constructor
A new instance of FileParser.
- #lines_pushed ⇒ Object
- #parse_line(line, index) ⇒ Object
- #push_comment ⇒ Object
Constructor Details
#initialize(file) ⇒ FileParser
Returns a new instance of FileParser.
8 9 10 11 12 13 |
# File 'lib/adjutant/file_parser.rb', line 8 def initialize(file) @text = file[:patch] @comment = Comment.new("") @comments = [] @previous_was_usefull = false end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
6 7 8 |
# File 'lib/adjutant/file_parser.rb', line 6 def comment @comment end |
Instance Method Details
#detect_comments ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/adjutant/file_parser.rb', line 15 def detect_comments lines_pushed.each_with_index do |line, index| line = Line.new(line) if line.usefull? || @previous_was_usefull parse_line(line, index) else push_comment and next end end push_comment if @previous_was_usefull @comments end |
#lines_pushed ⇒ Object
44 45 46 47 48 |
# File 'lib/adjutant/file_parser.rb', line 44 def lines_pushed @text .split(/(\n)/) .delete_if { |e| e[0] != "+" } end |
#parse_line(line, index) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/adjutant/file_parser.rb', line 35 def parse_line(line, index) if line.end_of_comment? push_comment else @comment.add line.usefull_text, index @previous_was_usefull = true end end |
#push_comment ⇒ Object
29 30 31 32 33 |
# File 'lib/adjutant/file_parser.rb', line 29 def push_comment @comments << @comment.print unless comment.text.nil? @comment.reset @previous_was_usefull = false end |