class Adjutant::FileParser

Attributes

comment[R]

Public Class Methods

new(file) click to toggle source
# File lib/adjutant/file_parser.rb, line 8
def initialize(file)
  @text = file[:patch]
  @comment = Comment.new("")
  @comments = []
  @previous_was_usefull = false
end

Public Instance Methods

detect_comments() click to toggle source
# 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() click to toggle source
# File lib/adjutant/file_parser.rb, line 44
def lines_pushed
  @text
    .split(/(\n)/)
    .delete_if { |e| e[0] != "+" }
end
parse_line(line, index) click to toggle source
# 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() click to toggle source
# 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