require 'aipim-rails/parser_helper' module Parser def self.init(filename) read_links(filename) read_content(filename) end def self.read_line(file) line = file.gets line = line.gsub("\n", "") unless line.nil? line end def self.read_links(filename) cenario_counter = 1 output = File.new("aipim/markdown.md", "w") file = File.new(filename, "r") while(line = read_line(file)) if ParserHelper.is_cenario?(line) output.puts "[#{cenario_counter}. #{ParserHelper.get_cenario(line)}](#) " cenario_counter = cenario_counter+1 end end file.close output.close end def self.read_content(filename) file = File.new(filename, "r") output = File.new("aipim/markdown.md", "a") screenshot = false cenario_counter = 1 result = %x[ls aipim/screenshots/].split("\n") counter_screenshot = 0 output.puts "" line = read_line(file) while (line) if !ParserHelper.is_comando?(line) && !(line.gsub(" ", "") == "") output.puts "#{line} " line = read_line(file) elsif ParserHelper.is_marcacao?(line) screenshot = true line = read_line(file) elsif ParserHelper.is_funcionalidade?(line) output.puts "# #{ParserHelper.get_funcionalidade(line)} #" line = read_line(file) elsif ParserHelper.is_cenario?(line) output.puts "> ## #{cenario_counter}. #{ParserHelper.get_cenario(line)} ##" cenario_counter = cenario_counter+1 while ((line = read_line(file)) && !ParserHelper.is_comando?(line)) if !(line.gsub(" ", "") == "") output.puts "> #{line} " end end if screenshot output.puts '> [![Alt text](screenshots/'+result[counter_screenshot].to_s+')](screenshots/'+result[counter_screenshot].to_s+') ' counter_screenshot = counter_screenshot+1 screenshot = false end output.puts '' output.puts '' output.puts '' elsif ParserHelper.is_contexto?(line) output.puts "## Contexto : #{ParserHelper.get_contexto(line)} ##" line = read_line(file) else line = read_line(file) end end file.close output.close end end