class ParseDecision::Controller
Controller
class handles interactions bewteen the view (cmdline script) and the model (Tool).
Public Class Methods
new()
click to toggle source
# File lib/parse_decision/controller.rb, line 22 def initialize() $LOG.debug "Controller::initialize" @cfg = Config.new.load @cfg = Config.new.load @model = Parser.new end
Public Instance Methods
execute()
click to toggle source
Save the current config values and start the parse.
# File lib/parse_decision/controller.rb, line 31 def execute() $LOG.debug "Controller::execute" # Save current cfg Config.new.save( @cfg ) @model.parseCfg( @cfg ) end
executeWithCmdLineArg(arg)
click to toggle source
Command line arg will be used as the outdir
.
# File lib/parse_decision/controller.rb, line 115 def executeWithCmdLineArg(arg) $LOG.debug "Controller::executeWithCmdLineArg( #{arg} )" @cfg[:outdir] = arg return true # if ok to continue, false to exit app. end
noCmdLineArg()
click to toggle source
Make sure outdir
has been set. Returns true as long as outdir is set one way or the other.
# File lib/parse_decision/controller.rb, line 124 def noCmdLineArg() $LOG.debug "Controller::noCmdLineArg" if( @cfg.key?(:outdir) && !@cfg[:outdir].empty? ) return true # if ok to continue, false to exit app. end puts "Missing output directory argument." puts puts "The outdir needs to be set at least one time." puts "Use the -o option or supply the output directory path on the command line." puts "Use -h for help." return false # to exit app. end
setOptions(options={})
click to toggle source
Set all options and switches with values from a hash.
# File lib/parse_decision/controller.rb, line 80 def setOptions(options={}) $LOG.debug "Controller::setOptions( options={} )" setSwitches(options) if(options.length) options.each do |opt, arg| case opt when :file # Set cfg decision file name @cfg[:file] = arg when :outdir # Set context output dir @cfg[:outdir] = arg when :srcdir # Set context src dir @cfg[:srcdir] = arg else # Don't know what you want but I don't recognize it. end end # options.each cfgCtrl = Config.new cfgCtrl.load cfgCtrl.cfg.merge!(@cfg) cfgCtrl.save end # if more than 1 option end
Private Instance Methods
setSwitches(options={})
click to toggle source
Set switches with values from a hash. This should only be called from setOptions
.
# File lib/parse_decision/controller.rb, line 41 def setSwitches(options={}) $LOG.debug "Controller::setSwitches( options={} )" if(options.length) options.each do |opt, arg| case opt when :logging cfgCtrl = Config.new cfgCtrl.load cfgCtrl.addKeyValue(:logging, arg) cfgCtrl.save when :reset cfgCtrl = Config.new cfgCtrl.save when :verbose # Set verbose flag @cfg[:verbose] = true when :version # Print the version and exit. verStr1 = "#{ParseDecision::APPNAME} v#{@model.version}" verStr2 = "#{ParseDecision::COPYRIGHT}" puts verStr1 puts verStr2 puts exit else # Don't know what you want but I don't recognize it. end # case opt end # options.each end # if more than 1 option end