Class: GdlDoc
- Inherits:
-
Object
- Object
- GdlDoc
- Defined in:
- lib/xmlutils/gdldoc.rb
Overview
class GdlDoc
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#srcPath ⇒ Object
readonly
Returns the value of attribute srcPath.
Instance Method Summary collapse
-
#buildLookupList ⇒ Object
————————————————————————————————————-# buildLookupList - Create a listing of lookup definitions from the context.
-
#createOutdir(outdir) ⇒ Object
————————————————————————————————————-# createOutdir - Create a directory if it does not exist.
-
#currentDate ⇒ Object
————————————————————————————————————-# currentDate - Generate today’s date string.
-
#definitionHeader(headerType) ⇒ Object
————————————————————————————————————-# definitionHeader - output collected variables to file.
-
#generate ⇒ Object
————————————————————————————————————-# generate - Generate a GDL document.
-
#generateRenameList ⇒ Object
————————————————————————————————————-# generateRenameList - Generate a CSV rename list.
-
#initialize(srcPath, ctx) ⇒ GdlDoc
constructor
A new instance of GdlDoc.
-
#outputDpm(var) ⇒ Object
————————————————————————————————————-# outputDpm - generate a GDL version of a DPM definition based on DPM XML element.
-
#outputDsm(var) ⇒ Object
————————————————————————————————————-# outputDsm - generate a GDL version of a DSM definition based on DSM XML element.
-
#outputFileHeader(ofile, infile) ⇒ Object
————————————————————————————————————-# outputFileHeader - output file header.
-
#outputPpm(var) ⇒ Object
————————————————————————————————————-# outputPpm - generate a GDL version of a PPM definition based on PPM XML element.
-
#outputRule(rule) ⇒ Object
————————————————————————————————————-# outputRule - generate a GDL version of a rule definition based on Rule XML element.
-
#outputRuleInfo(ofile) ⇒ Object
————————————————————————————————————-# outputRuleInfo - output collected variables to file.
-
#setOptions(flgs) ⇒ Object
————————————————————————————————————# setOptions - Set configuration option flags.
Constructor Details
#initialize(srcPath, ctx) ⇒ GdlDoc
Returns a new instance of GdlDoc.
29 30 31 32 33 |
# File 'lib/xmlutils/gdldoc.rb', line 29 def initialize(srcPath, ctx) super() @srcPath = srcPath @context = ctx end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
23 24 25 |
# File 'lib/xmlutils/gdldoc.rb', line 23 def context @context end |
#srcPath ⇒ Object (readonly)
Returns the value of attribute srcPath.
24 25 26 |
# File 'lib/xmlutils/gdldoc.rb', line 24 def srcPath @srcPath end |
Instance Method Details
#buildLookupList ⇒ Object
————————————————————————————————————-# buildLookupList - Create a listing of lookup definitions from the context
————————————————————————————————————#
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/xmlutils/gdldoc.rb', line 297 def buildLookupList() lkups = Hash.new lkList = "" tpl = GdlTemplate.new @context.lookups.each do |lkName, lkup| params = @context.getLookupParamNames(lkName) lkups[lkName] = tpl.lookup(lkName, params["xparam"], params["yparam"]) # lkList += tpl.lookup(lkName, params["xparam"], params["yparam"]) # lkList += ";\n" # Put each lookup on a seperate line end # do sorted = lkups.sort {|a, b| a[0].downcase <=> b[0].downcase} sorted.each do |item| lkList += "#{item[1]};\n" end # do sorted return lkList end |
#createOutdir(outdir) ⇒ Object
————————————————————————————————————-# createOutdir - Create a directory if it does not exist
outdir - Directory name/path to create
————————————————————————————————————#
326 327 328 329 330 331 |
# File 'lib/xmlutils/gdldoc.rb', line 326 def createOutdir(outdir) if( !File.directory?(outdir) ) FileUtils.makedirs("#{outdir}") end end |
#currentDate ⇒ Object
————————————————————————————————————-# currentDate - Generate today’s date string
————————————————————————————————————#
71 72 73 74 |
# File 'lib/xmlutils/gdldoc.rb', line 71 def currentDate() now = DateTime::now() return now.strftime("%m/%d/%Y %H:%M:%S") end |
#definitionHeader(headerType) ⇒ Object
————————————————————————————————————-# definitionHeader - output collected variables to file
headerType - Header type (ex: DSM)
————————————————————————————————————#
365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/xmlutils/gdldoc.rb', line 365 def definitionHeader(headerType) header = "\n\n\n\n// ---------------------------- \#{headerType} definitions ----------------------------\n\n" header end |
#generate ⇒ Object
————————————————————————————————————-# generate - Generate a GDL document
returns string - generated file name
————————————————————————————————————#
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/xmlutils/gdldoc.rb', line 85 def generate() destDir = @context.[:destdir] destFile = @context.[:destfile] if(nil == destFile || destFile.empty?) destFile = File.basename(@srcPath, ".xml") + ".gdl" end if ($DEBUG) puts "generate:" puts " sourcePath: #{@srcPath}" puts " destDir: #{destDir}" puts " destFile: #{destFile}" puts " context: #{@context}" end # if $DEBUG tpl = GdlTemplate.new genFile = File.join(destDir, destFile) createOutdir(destDir) File.open("#{genFile}", "w") do |ofile| ofile << tpl.fileHeader(@srcPath, currentDate() ) ofile << tpl.sectionComment("DPM Definitions") vars = @context.dpms.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} vars.each do |rDpm| dpm = rDpm[1] if (dpm.varType == "DPM") ofile << tpl.dpm(dpm.prodType, dpm.name, dpm.alias) end # if dpm end # do # @context.dpms.each do |key, dpm| # if (dpm.varType == "DPM") # ofile << tpl.dpm(dpm.prodType, dpm.name, dpm.alias) # end # if dpm # end # dpms.each ofile << tpl.sectionComment("DSM Definitions") vars = @context.dpms.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} vars.each do |rDpm| dpm = rDpm[1] if (dpm.varType == "DSM") ofile << tpl.dsm(dpm.prodType, dpm.name, dpm.alias) end # if dpm end # do # @context.dpms.each do |key, dpm| # if (dpm.varType == "DSM") # ofile << tpl.dsm(dpm.prodType, dpm.name, dpm.alias) # end # if dsm # end # dsms.each #@context.ppms.each do |p| # puts p.inspect #end # @context.ppms consists of an array of [ppm alias, ppm object]s #vars = @context.ppms.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} prds = @context.ppms.select {|a,b| b.varType == "prd"} prds.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} apps = @context.ppms.select {|a,b| b.varType == "app"} apps.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} crds = @context.ppms.select {|a,b| b.varType == "crd"} crds.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} ofile << tpl.sectionComment("PPM Definitions (PRD)") prds.each do |rPpm| ppm = rPpm[1] ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias) end # do ofile << tpl.sectionComment("PPM Definitions (APP)") apps.each do |rPpm| ppm = rPpm[1] ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias) end # do ofile << tpl.sectionComment("PPM Definitions (CRD)") crds.each do |rPpm| ppm = rPpm[1] ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias) end # do # @context.ppms.each do |key, ppm| # ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias) # end # ppms.each ofile << tpl.multiLineComment(buildLookupList(), "Lookups that need to be imported") ofile << tpl.sectionComment("Rule Definitions") rules = @context.rules.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} rules.each do |rrule| rule = rrule[1] ofile << tpl.rule(rule) end # do # @context.rules.each do |key, rule| # ofile << tpl.rule(rule) # end # rules.each ofile << tpl.sectionComment("Ruleset Definitions") rulesets = @context.rulesets.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase} rulesets.each do |rruleset| ruleset = rruleset[1] ofile << tpl.ruleset(ruleset, @context) end # do # @context.rulesets.each do |key, ruleset| # ofile << tpl.ruleset(ruleset, @context) # end # ruleset.each ofile << tpl.sectionComment("Guideline Definition") ofile << tpl.guideline(@context) end return genFile end |
#generateRenameList ⇒ Object
————————————————————————————————————-# generateRenameList - Generate a CSV rename list
returns string - generated file name
————————————————————————————————————#
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/xmlutils/gdldoc.rb', line 232 def generateRenameList() destDir = @context.[:destdir] destFile = @context.[:destfile] if(nil == destFile || destFile.empty?) destFile = File.basename(@srcPath, ".xml") + ".gdl" end destFile = File.basename(destFile, ".gdl") + ".rename.csv" if ($DEBUG) puts "generateRenameList:" puts " sourcePath: #{@srcPath}" puts " destDir: #{destDir}" puts " context: #{@context}" end # if $DEBUG genFile = File.join(destDir, destFile) createOutdir(destDir) File.open("#{genFile}", "w") do |ofile| # Don't add to list if alias has '.'. # Don't add to list if alias and name are identical. vars = @context.rules.sort {|a, b| a[0].downcase <=> b[0].downcase} vars.each do |ruleAry| rule = ruleAry[1] if (ruleAry[0] != rule.name) if (nil == ruleAry[0].index('.')) ofile << "rule,#{ruleAry[0]},#{rule.name}\n" end # if no period end # if name and alias do not match end # do # Don't add to list if ruleset is powerlookup. # Don't add to list if alias and name are identical. vars = @context.rulesets.sort {|a, b| a[0].downcase <=> b[0].downcase} vars.each do |rulesetAry| ruleset = rulesetAry[1] if ("PL" != ruleset.type) if (rulesetAry[0] != ruleset.name) ofile << "ruleset,#{rulesetAry[0]},#{ruleset.name}\n" end # if not identical end # if not PL ruleset end # do end return genFile end |
#outputDpm(var) ⇒ Object
————————————————————————————————————-# outputDpm - generate a GDL version of a DPM definition based on DPM XML element
var - XML element to generate output for
————————————————————————————————————#
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/xmlutils/gdldoc.rb', line 468 def outputDpm(var) xVarType = var.attribute('ProductType').to_s case xVarType when '1' varType = "boolean" when '2' varType = "date" when '3' varType = "money" when '4' varType = "numeric" when '5' varType = "percentage" when '6' varType = "text" end varAlias = var.attribute('Alias') varName = var.attribute('Name') out = "dpm \#{varType} \#{varName} \"\#{varAlias}\";\n" out # Return generated output end |
#outputDsm(var) ⇒ Object
————————————————————————————————————-# outputDsm - generate a GDL version of a DSM definition based on DSM XML element
var - XML element to generate output for
————————————————————————————————————#
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/xmlutils/gdldoc.rb', line 425 def outputDsm(var) xVarType = var.attribute('ProductType').to_s case xVarType when '1' varType = "boolean" when '2' varType = "date" when '3' varType = "money" when '4' varType = "numeric" when '5' varType = "percentage" when '6' varType = "text" end varAlias = var.attribute('Alias') varName = var.attribute('Name') out = "decision dpm \#{varType} \#{varName} \"\#{varAlias}\";\n" out # Return generated output end |
#outputFileHeader(ofile, infile) ⇒ Object
————————————————————————————————————-# outputFileHeader - output file header
ofile - output file to write header to infile - Name of file to create header for
————————————————————————————————————#
343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/xmlutils/gdldoc.rb', line 343 def outputFileHeader(ofile, infile) header = "/* **************************************************************************\n * File: \#{infile}.gdl\n * Generated guideline\n *\n * *************************************************************************/\n\n\n" ofile << header end |
#outputPpm(var) ⇒ Object
————————————————————————————————————-# outputPpm - generate a GDL version of a PPM definition based on PPM XML element
var - XML element to generate output for
————————————————————————————————————#
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/xmlutils/gdldoc.rb', line 390 def outputPpm(var) xVarType = "text" xvarSection = var.attribute('Type').to_s case xvarSection when 'APM' varSection = "app" when 'PRD' varSection = "prd" when 'CRP' varSection = "crd" end varAlias = var.attribute('Alias') varName = var.attribute('Name') out = "ppm \#{xVarType} \#{varSection} p\#{varName} \"\#{varAlias}\";\n" out # Return generated output end |
#outputRule(rule) ⇒ Object
————————————————————————————————————-# outputRule - generate a GDL version of a rule definition based on Rule XML element
rule - XML element to generate output for
————————————————————————————————————#
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/xmlutils/gdldoc.rb', line 530 def outputRule(rule) # arule = root.elements['//Rule'].to_a # returns all 1st level rule children elements ruleParts = rule.elements.to_a puts "" puts "Rule Parts:" puts "#{ruleParts.inspect}" puts "" visitor = XmlRuleVisitor.new output = "" visitor.lookupData = @lookupData return visitor.visit(rule, output) end |
#outputRuleInfo(ofile) ⇒ Object
————————————————————————————————————-# outputRuleInfo - output collected variables to file
ofile - output file handle
————————————————————————————————————#
511 512 513 514 515 516 517 518 519 |
# File 'lib/xmlutils/gdldoc.rb', line 511 def outputRuleInfo(ofile) ofile << definitionHeader("Rule") @rules.each_value do |rule| ofile << outputRule(rule) end end |
#setOptions(flgs) ⇒ Object
————————————————————————————————————# setOptions - Set configuration option flags
flg - Array of options or single string option. Currently, only -v: verbose is available
————————————————————————————————————#
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/xmlutils/gdldoc.rb', line 44 def setOptions(flgs) if (flgs.class == Array) flgs.each do |f| case f when '-v' @verbose = true end end # flgs.each return end # if flgs case flgs when '-v' @verbose = true end end |