class ParseDecision::Parser
The Parser
class runs the show. This class is called by the controller object
Public Class Methods
new()
click to toggle source
# File lib/parse_decision/parser.rb, line 26 def initialize() $LOG.debug "Parser::initialize" @cfg = Config.new.load @plugins = [Plugin::Application.new, Plugin::PpmXpath.new, Plugin::PreDecisionGuideline.new, Plugin::ProductXpath.new, Plugin::Product.new, ] @context = PDContext.new end
Public Instance Methods
configureForFileMode(fname)
click to toggle source
# File lib/parse_decision/parser.rb, line 132 def configureForFileMode(fname) $LOG.debug "Parser::configureForFileMode( #{fname} )" mode = :default fileTypeFound = false # Open the file and read line by line looking for indications of which mode to use. df = File.open(fname).each do |ln| # Search for 'normal' decision file. if(ln.include?("<PARAMS>")) fileTypeFound = true puts "Decision file type = :default (not webdecision)" if @context.verbose break end # Search for web decision file. if(ln.include?("Next Decision")) fileTypeFound = true mode = :webdecision puts "Decision file type = :webdecision" if @context.verbose break end # Exit file search if mode has been determined. if(true == fileTypeFound) break end end # do file # If the file is a web decision, reset the plugins. if(mode == :webdecision) @context.parseMode = mode @plugins = [Plugin::Application.new, Plugin::WebProduct.new, ] end end
noCmdLineArg()
click to toggle source
# File lib/parse_decision/parser.rb, line 186 def noCmdLineArg() $LOG.debug "Parser::noCmdLineArg" end
parse(srcpath, destpath)
click to toggle source
# File lib/parse_decision/parser.rb, line 73 def parse(srcpath, destpath) path = Pathname.new srcpath destpath = Pathname.pwd if destpath.nil? parseCfg({ file: path.basename.to_s, srcdir: path.dirname.to_s, outdir: destpath.to_s }) end
parseCfg(cfg)
click to toggle source
Parse files based on the configuration.
# File lib/parse_decision/parser.rb, line 81 def parseCfg(cfg) $LOG.debug "Parser::parseCfg( cfg )" if( !validateCfg(cfg) ) puts "ERROR: Invalid options." return end if( !File.exists?(@context.file) ) @context.file = File.join( @context.srcdir, @context.file ) if( !File.exists?(@context.file) ) puts "ERROR: unable to locate src file: #{@context.file}" return end end if( !File.exists?(@context.outdir) ) FileUtils.mkdir_p( @context.outdir ) puts "Output dir created: #{@context.outdir}" if @context.verbose end parseFile(@context.file) # Copy the decision log to the output dir. FileUtils.cp(@context.file, @context.outdir) end
parseFile(fname)
click to toggle source
Parse an XML decision file.
# File lib/parse_decision/parser.rb, line 110 def parseFile(fname) $LOG.debug "Parser::parseFile( #{fname} )" puts "Parsing file: #{fname}" if @context.verbose # Determine the mode and configure plugins based on the file data. configureForFileMode(fname) line_count = 1 # Open the file and read line by line df = File.open(fname).each do |ln| puts line_count.to_s if $DEBUG line_count += 1 @plugins.each do |plug| puts " --> #{plug.class}" if $DEBUG break if ( true == plug.execute(@context, ln)) end # plugins.each end # do file puts "Lines parsed: #{line_count}" if @context.verbose end
parseFileWithCmdLineArg(arg)
click to toggle source
# File lib/parse_decision/parser.rb, line 177 def parseFileWithCmdLineArg(arg) $LOG.debug "Parser::parseFileWithCmdLineArg( #{arg} )" end
parseFileWithSwitch(arg)
click to toggle source
# File lib/parse_decision/parser.rb, line 172 def parseFileWithSwitch(arg) $LOG.debug "Parser::parseFileWithSwitch( #{arg} )" end
setOutdir(dir)
click to toggle source
Set directory where generated files are placed.
# File lib/parse_decision/parser.rb, line 182 def setOutdir(dir) @context.outdir = dir end
validateCfg(cfg)
click to toggle source
Validate the configuration.
# File lib/parse_decision/parser.rb, line 46 def validateCfg(cfg) if(!(cfg.key?(:file) && (nil != cfg[:file]))) puts "Missing --file option." return false end if(!(cfg.key?(:outdir) && (nil != cfg[:outdir])) ) puts "Missing --outdir option." return false end @context.file = cfg[:file] @context.outdir = cfg[:outdir] if(cfg.key?(:srcdir) && cfg[:srcdir] != nil) @context.srcdir = cfg[:srcdir] end if(cfg.key?(:verbose) && cfg[:verbose] != nil) @context.verbose = cfg[:verbose] end return true end
version()
click to toggle source
Return the application’s version string.
# File lib/parse_decision/parser.rb, line 40 def version() return ParseDecision::VERSION end