Class: GdlDocBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlutils/gdldocbuilder.rb

Overview

class GdlDocBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GdlDocBuilder

————————————————————————————————————-# initialize - CTor

options - Document builder options

————————————————————————————————————#



32
33
34
35
36
# File 'lib/xmlutils/gdldocbuilder.rb', line 32

def initialize(options)
  @options  = options
  @context  = GdlContext.new
  @context.setOptions(@options)
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



22
23
24
# File 'lib/xmlutils/gdldocbuilder.rb', line 22

def context
  @context
end

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/xmlutils/gdldocbuilder.rb', line 21

def options
  @options
end

Instance Method Details

#createDocument(srcFile) ⇒ Object

————————————————————————————————————-# createDocument - create a GDL document from an XML document

srcFile - XML source file

————————————————————————————————————#



47
48
49
50
51
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
# File 'lib/xmlutils/gdldocbuilder.rb', line 47

def createDocument(srcFile)

  # Setup context object builder

  ctxBuilder = ContextParser.new(@context)
  ctxBuilder.setFlag(@options)

  statusMsg "Creating guideline context."

  ctxBuilder.parse(srcFile)

  printMetrics(@context)



  statusMsg "Parsing external variable definitions."

  parseExternalVarDefs(@context)



  statusMsg "Parsing rule data (#{ctxBuilder.context.rules.size.to_s} rules)."

  ruleBuilder = RuleParser.new(@context)
  ruleBuilder.setFlag(@options)

  @context.rules.each do |key, rule|
    rule.src = ruleBuilder.parse(rule.xml)
    print "."
  end # rules.each

  puts


#   ctxBuilder.dumpResults



  # Create output file and output src.

  statusMsg "Generating document."

  gdlDoc = GdlDoc.new(srcFile, @context)
  gdlDoc.setOptions(@options)

  genFile = gdlDoc.generate

  statusMsg "Document created: #{genFile}"

  genFile = gdlDoc.generateRenameList

  statusMsg "Rename list document created: #{genFile}"

end

#parseExternalVarDefs(ctx) ⇒ Object

————————————————————————————————————-# parseExternalVarDefs - parse predefined GDL variable definition files.

ctx - context containing variables to update

————————————————————————————————————#



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
# File 'lib/xmlutils/gdldocbuilder.rb', line 144

def parseExternalVarDefs(ctx)
  puts "No external variable definition files provided." if (!ctx.options[:verbose].nil? && ctx.options[:includes].nil?)
  return if ctx.options[:includes].nil?

  vp = LineParser.new                     # Parse externally defined GDL variable definition files.

  ctx.options[:includes].each do |inc|
    vp.parse(inc)     # TODO: Allow external var def files to be defined in a config file.

  end # ctx.options.each


  vp.dumpResults if $DEBUG

  puts "Searching for external DPM definitions." if $DEBUG
  ctx.dpms.each do |key, val|
    if (vp.dpms.has_key?(key))
      ctx.dpms[key] = vp.dpms[key]
      puts "Found match: #{key}" if $DEBUG
    end # if vp.dpms

  end # do


  puts "Searching for external DSM definitions." if $DEBUG
  ctx.dpms.each do |key, val|
    if (vp.dsms.has_key?("#{key}"))
      ctx.dpms[key] = vp.dsms[key]
      puts "Found match: #{key}" if $DEBUG
    end # if vp.dsms

  end # do


  puts "Searching for external PPM definitions." if $DEBUG
  ctx.ppms.each do |key, val|
    if (vp.ppms.has_key?(key))
      ctx.ppms[key] = vp.ppms[key]
      puts "Found match: #{key}" if $DEBUG
    end # if vp.ppms

  end # do


end

#printMetrics(ctx) ⇒ Object

————————————————————————————————————-# printMetrics - Print context metrics

ctx - Context to generate metrics from

————————————————————————————————————#



124
125
126
127
128
129
130
131
132
133
# File 'lib/xmlutils/gdldocbuilder.rb', line 124

def printMetrics(ctx)

  puts "        DPM count: #{ctx.dpms.size.to_s}  (includes DSMs)"
  puts "        PPM count: #{ctx.ppms.size.to_s}"
  puts "     Lookup count: #{ctx.lookups.size.to_s}"
  puts "    Message count: #{ctx.messages.size.to_s}  (includes conditions)"
  puts "       Rule count: #{ctx.rules.size.to_s}"
  puts "    Ruleset count: #{ctx.rulesets.size.to_s}"

end

#statusMsg(msg) ⇒ Object

————————————————————————————————————-# statusMsg - output a status message

msg - Message to output

————————————————————————————————————#



107
108
109
110
111
112
113
# File 'lib/xmlutils/gdldocbuilder.rb', line 107

def statusMsg(msg)

  puts
  puts "-} #{msg}"
  puts

end