Class: ParseDecision::PDContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializePDContext

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

#fileObject

Returns the value of attribute file.



27
28
29
# File 'lib/parse_decision/pd_context.rb', line 27

def file
  @file
end

#indexObject (readonly)

Returns the value of attribute index.



29
30
31
# File 'lib/parse_decision/pd_context.rb', line 29

def index
  @index
end

#outdirObject

Returns the value of attribute outdir.



25
26
27
# File 'lib/parse_decision/pd_context.rb', line 25

def outdir
  @outdir
end

#parseModeObject

Returns the value of attribute parseMode.



31
32
33
# File 'lib/parse_decision/pd_context.rb', line 31

def parseMode
  @parseMode
end

#srcdirObject

Returns the value of attribute srcdir.



26
27
28
# File 'lib/parse_decision/pd_context.rb', line 26

def srcdir
  @srcdir
end

#stateObject

Returns the value of attribute state.



30
31
32
# File 'lib/parse_decision/pd_context.rb', line 30

def state
  @state
end

#verboseObject

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

#availableStatesObject

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

#dataObject

Return the data hash, creating it if needed.



51
52
53
# File 'lib/parse_decision/pd_context.rb', line 51

def data()
  @data ||= {}
end

#indexStrObject



129
130
131
# File 'lib/parse_decision/pd_context.rb', line 129

def indexStr()
  return "%03d" % @index
end

#nextIndexObject



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