Class: ParseDecision::PDContext
- Inherits:
-
Object
- Object
- ParseDecision::PDContext
- Defined in:
- lib/parse_decision/pd_context.rb
Overview
Context class holds all info and state about the current parsing process
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#outdir ⇒ Object
Returns the value of attribute outdir.
-
#parseMode ⇒ Object
Returns the value of attribute parseMode.
-
#srcdir ⇒ Object
Returns the value of attribute srcdir.
-
#state ⇒ Object
Returns the value of attribute state.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#[](sym) ⇒ Object
Return data from hash.
-
#[]=(sym, val) ⇒ Object
Return data from hash.
-
#availableStates ⇒ Object
Return array of current available states.
- #createValidName(inname) ⇒ Object
-
#data ⇒ Object
Return the data hash, creating it if needed.
- #indexStr ⇒ Object
-
#initialize ⇒ PDContext
constructor
A new instance of PDContext.
- #nextIndex ⇒ Object
-
#outputPath(filename) ⇒ Object
Return the full output path including the filename.
-
#src_file=(file) ⇒ Object
Set source file and dir path.
Constructor Details
#initialize ⇒ PDContext
Returns a new instance of PDContext.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/parse_decision/pd_context.rb', line 34 def initialize() $LOG.debug "PDContext::initialize" @outdir = nil @srcdir = "." @file = nil @verbose = false @index = 0 @parseMode = :default # :webdecision @data = nil # Hash to store plugin data in @availableStates = {} @availableStates[:default] = [:app, :appPpmXpath, :preDecisionGdl, :productXpath, :productXml, :productPpms, :productRules, ] @availableStates[:webdecision] = [:app, :gdlRules, :productRules, :decisionResponse, :preDecisionGdl, ] end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
27 28 29 |
# File 'lib/parse_decision/pd_context.rb', line 27 def file @file end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
29 30 31 |
# File 'lib/parse_decision/pd_context.rb', line 29 def index @index end |
#outdir ⇒ Object
Returns the value of attribute outdir.
25 26 27 |
# File 'lib/parse_decision/pd_context.rb', line 25 def outdir @outdir end |
#parseMode ⇒ Object
Returns the value of attribute parseMode.
31 32 33 |
# File 'lib/parse_decision/pd_context.rb', line 31 def parseMode @parseMode end |
#srcdir ⇒ Object
Returns the value of attribute srcdir.
26 27 28 |
# File 'lib/parse_decision/pd_context.rb', line 26 def srcdir @srcdir end |
#state ⇒ Object
Returns the value of attribute state.
30 31 32 |
# File 'lib/parse_decision/pd_context.rb', line 30 def state @state end |
#verbose ⇒ Object
Returns the value of attribute verbose.
28 29 30 |
# File 'lib/parse_decision/pd_context.rb', line 28 def verbose @verbose end |
Instance Method Details
#[](sym) ⇒ Object
Return data from hash.
57 58 59 |
# File 'lib/parse_decision/pd_context.rb', line 57 def [](sym) return data[sym] end |
#[]=(sym, val) ⇒ Object
Return data from hash.
63 64 65 |
# File 'lib/parse_decision/pd_context.rb', line 63 def []=(sym, val) return data[sym] = val end |
#availableStates ⇒ Object
Return array of current available states.
69 70 71 |
# File 'lib/parse_decision/pd_context.rb', line 69 def availableStates() return @availableStates[@parseMode] end |
#createValidName(inname) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/parse_decision/pd_context.rb', line 134 def createValidName(inname) return nil if nil == inname outname = inname.gsub(/[\s\/\\?*#+]/,'') # Remove illegal chars (replace with underscore). outname.gsub!(/_+/,"_") # Replace consecutive uscores with single uscore. outname.gsub!(/\./,"-") # Replace period with dash. outname.gsub!(/[\(\)\$]/,"") # Remove L & R Parens, dollar signs. outname.gsub!(/\%/,"Perc") # Replace '%' with Perc. outname end |
#data ⇒ Object
Return the data hash, creating it if needed.
51 52 53 |
# File 'lib/parse_decision/pd_context.rb', line 51 def data() @data ||= {} end |
#indexStr ⇒ Object
129 130 131 |
# File 'lib/parse_decision/pd_context.rb', line 129 def indexStr() return "%03d" % @index end |
#nextIndex ⇒ Object
125 126 127 |
# File 'lib/parse_decision/pd_context.rb', line 125 def nextIndex() @index += 1 end |
#outputPath(filename) ⇒ Object
Return the full output path including the filename.
112 113 114 115 |
# File 'lib/parse_decision/pd_context.rb', line 112 def outputPath(filename) raise "outdir missing" unless !@outdir.nil? outputPath = File.join(@outdir, filename) end |
#src_file=(file) ⇒ Object
Set source file and dir path
87 88 89 90 91 |
# File 'lib/parse_decision/pd_context.rb', line 87 def src_file=(file) fp = Pathname.new(file) @srcdir = fp.dirname.to_s @file = fp.basename.to_s end |