Class: GreenPepper::GreenPepperCore
- Inherits:
-
Object
- Object
- GreenPepper::GreenPepperCore
- Defined in:
- lib/greenpepper/core.rb
Instance Method Summary collapse
-
#initialize(log = Logger.new(STDERR)) ⇒ GreenPepperCore
constructor
A new instance of GreenPepperCore.
-
#run(args) ⇒ Object
entry point for the application.
Constructor Details
#initialize(log = Logger.new(STDERR)) ⇒ GreenPepperCore
Returns a new instance of GreenPepperCore.
29 30 31 32 33 34 |
# File 'lib/greenpepper/core.rb', line 29 def initialize(log = Logger.new(STDERR)) @log = log # Disable libXML stderr output LibXML::XML::Error.reset_handler end |
Instance Method Details
#run(args) ⇒ Object
entry point for the application
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/greenpepper/core.rb', line 39 def run(args) argument_parser = ArgumentParser.new args execution_context = argument_parser.execution_context @writer_options = argument_parser.writer_context LoadPath.load execution_context[:load_path] console_output = execution_context[:console_output] unless console_output == "" puts console_output @log.log console_output return end begin results_array = Array.new table_pass = TablePass.new freetext_pass = FreeTextPass.new GreenPepperPass.passes = [freetext_pass, table_pass] execution_units = [] interpreted_html = read_input_file(execution_context) # Don't execute if input file is empty if interpreted_html.strip != "" execution_units, interpreted_html = GreenPepperPass.interpret interpreted_html, execution_context[:input_document], @writer_options results_array = ExecutionUnit.result_list(execution_units) if execution_context[:html_results_output] && !execution_context[:xml_output] interpreted_html = write_results interpreted_html, results_array end end console_output = ConsoleOutput.new console_output.print_output ConsoleWriter.new(results_array).output if execution_context[:xml_output] xml_writer = XmlWriter.new interpreted_html interpreted_html = xml_writer.write_results results_array end output = FileOutput.new execution_context[:output_document] output.print_output interpreted_html return results_array rescue GreenPepperLibXmlError, GreenPepperMalformedTableError => ex @log.log_error "#{ex.to_s}\n #{print_backtrace ex.backtrace}" return -1 rescue Exception => ex @log.error "Internal Error." @log.log "#{ex.to_s}\n #{print_backtrace ex.backtrace}" raise ex end return 0 end |