Class: ParseDecision::Plugin::WebProduct
- Defined in:
- lib/parse_decision/plugin/web_product.rb
Overview
####################################################################### Product info plugin - specific to webdecisions
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #execute(context, ln) ⇒ Object
- #getSubString(haystack, startDelim, stopDelim) ⇒ Object
-
#initialize ⇒ WebProduct
constructor
A new instance of WebProduct.
- #productIndexStr ⇒ Object
- #renameFile(context, srcFileName, destFileName) ⇒ Object
Methods inherited from Plugin
#apply_template, #apply_templates, #write_to_file
Constructor Details
#initialize ⇒ WebProduct
Returns a new instance of WebProduct.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/parse_decision/plugin/web_product.rb', line 21 def initialize() $LOG.debug "WebProduct::initialize" @fnameTemplate = "@INDEX@-@[email protected]" @ruleStartStr = "<Rules>" @gdlStartStr = "<Decision GuidelineId" @stopStr = "</Decision>" @openProgramNameDpm = '>' @closeProgramNameDpm = '</DPM>' @data = [] @outfile = "" @openTag = "<@TAG@_DATA>\n" @closeTag = "</@TAG@_DATA>\n" @openTag = "<PRODUCT_DATA>\n" @closeTag = "</PRODUCT_DATA>\n" @lineCount = 0 @chunkSize = 1000 @product = "" @productIndex = 1 @appIndex = "00" end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/parse_decision/plugin/web_product.rb', line 19 def data @data end |
Instance Method Details
#execute(context, ln) ⇒ Object
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/parse_decision/plugin/web_product.rb', line 52 def execute(context, ln) #$LOG.debug "WebProduct::execute" if((context.state == :app) && ln.include?(@ruleStartStr)) context.state = :gdlRules @data.clear @outfile = "" context["programNameFound"] = false context["productName"] = "" if(!@appIndex.eql?(context.indexStr)) @productIndex = 1 @appIndex = context.indexStr end product = "Product" + productIndexStr() @productIndex += 1 @product = context.createValidName(product) @outfile = apply_templates(@fnameTemplate, {"@INDEX@"=>context.indexStr, "@PROD@"=>@product}) puts "" if context.verbose puts "- + - + - + -" if context.verbose puts "" if context.verbose puts "Creating product file: #{@outfile}" if context.verbose @data << ln File.open(context.outputPath(@outfile), "w") do |f| write_to_file(f,@openTag) # apply_template(@openTag, "@TAG@", context.createValidName(@product)) write_to_file(f,context[:productXpath]) if ! context[:productXpath].nil? write_to_file(f,@data) end @data.clear return true end if((context.state == :gdlRules)) context.state = :productRules @data << ln return true end if((context.state == :productRules) && !ln.include?(@stopStr)) if(ln.include?("----")) # Skip comment lines (they are not valid XML). commentLine = ln.slice(0,4) return true if(commentLine.include?("----")) end @data << ln @lineCount += 1 if(!context["programNameFound"]) if(ln.include?('Name="Program Name"')) productName = getSubString(ln, @openProgramNameDpm, @closeProgramNameDpm) context["programNameFound"] = true context["productName"] = productName puts "........Program Name DPM found: #{productName}" if context.verbose end # if ln.include? end # if !context["programNameFound"] if(@lineCount > @chunkSize) puts "Writing rule data chunk." if context.verbose File.open(context.outputPath(@outfile), "a") do |f| write_to_file(f,@data) end @lineCount = 0 @data.clear end return true end if((context.state == :productRules) && ln.include?(@stopStr)) @data << ln @lineCount += 1 puts "Closing product file." if context.verbose File.open(context.outputPath(@outfile), "a") do |f| write_to_file(f,@data) write_to_file(f,@closeTag) # apply_template(@closeTag, "@TAG@", context.createValidName(@product)) end @lineCount = 0 @data.clear context.state = :app #@productIndex = 1 if(context["programNameFound"]) pname = context.createValidName(context["productName"]) newFileName = apply_templates(@fnameTemplate, {"@INDEX@"=>context.indexStr, "@PROD@"=>pname}) renameFile(context, @outfile, newFileName) end # if context["programNameFound"] context["programNameFound"] = false return true end return false end |
#getSubString(haystack, startDelim, stopDelim) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/parse_decision/plugin/web_product.rb', line 151 def getSubString(haystack, startDelim, stopDelim) #$LOG.debug "WebProduct::getSubString( #{haystack}, #{startDelim}, #{stopDelim} )" #puts "WebProduct::getSubString()" # #{haystack}, #{startDelim}, #{stopDelim} )" #puts " haystack: #{haystack}" #puts " startDelim: #{startDelim}" #puts " stopDelim: #{stopDelim}" start = haystack.index(startDelim) #puts " start: " + (start.nil? ? "nil" : "#{start}") return if start.nil? start += startDelim.size stop = haystack.rindex(stopDelim) res = haystack[start,(stop - start)] end |
#productIndexStr ⇒ Object
47 48 49 |
# File 'lib/parse_decision/plugin/web_product.rb', line 47 def productIndexStr() return "%02d" % @productIndex end |
#renameFile(context, srcFileName, destFileName) ⇒ Object
169 170 171 172 |
# File 'lib/parse_decision/plugin/web_product.rb', line 169 def renameFile(context, srcFileName, destFileName) puts "Renaming #{srcFileName} => #{destFileName}" if context.verbose FileUtils.mv(context.outputPath(srcFileName), context.outputPath(destFileName)) end |