Class: GdlListener

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

Overview

class GdlListener

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ GdlListener

Returns a new instance of GdlListener.



37
38
39
40
41
42
43
44
# File 'lib/xmlutils/gdllistener.rb', line 37

def initialize(ctx)
  super()
  @context      = ctx
  @gdl          = nil
  @inGuideline  = false
  @inRule       = false
  @inRuleset    = false
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



25
26
27
# File 'lib/xmlutils/gdllistener.rb', line 25

def context
  @context
end

#gdl=(value) ⇒ Object (writeonly)

Sets the attribute gdl

Parameters:

  • value

    the value to set the attribute gdl to.



26
27
28
# File 'lib/xmlutils/gdllistener.rb', line 26

def gdl=(value)
  @gdl = value
end

#inGuideline=(value) ⇒ Object (writeonly)

Sets the attribute inGuideline

Parameters:

  • value

    the value to set the attribute inGuideline to.



28
29
30
# File 'lib/xmlutils/gdllistener.rb', line 28

def inGuideline=(value)
  @inGuideline = value
end

#inRule=(value) ⇒ Object (writeonly)

Sets the attribute inRule

Parameters:

  • value

    the value to set the attribute inRule to.



29
30
31
# File 'lib/xmlutils/gdllistener.rb', line 29

def inRule=(value)
  @inRule = value
end

#inRuleset=(value) ⇒ Object (writeonly)

Sets the attribute inRuleset

Parameters:

  • value

    the value to set the attribute inRuleset to.



30
31
32
# File 'lib/xmlutils/gdllistener.rb', line 30

def inRuleset=(value)
  @inRuleset = value
end

Instance Method Details

#closeGuidelineObject

————————————————————————————————————-# closeGuideline - Close a Guideline object

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



156
157
158
159
160
161
162
163
164
165
# File 'lib/xmlutils/gdllistener.rb', line 156

def closeGuideline()
  if (inGuideline?)
    @GuidelineOpen = false
    @context.guideline = @gdl

    puts "closeGuideline" unless (!$DEBUG)
    puts "" unless (!$DEBUG)
  end # if


end

#closeRuleObject

————————————————————————————————————-# closeRule - Close a rule object

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



206
207
208
209
210
211
212
213
214
# File 'lib/xmlutils/gdllistener.rb', line 206

def closeRule()
  if (inRule?)
    @inRule = false

    puts "closeRule" unless (!$DEBUG)
    puts "" unless (!$DEBUG)
  end # if


end

#closeRulesetObject

————————————————————————————————————-# closeRuleset - Close a ruleset object

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



255
256
257
258
259
260
261
262
263
# File 'lib/xmlutils/gdllistener.rb', line 255

def closeRuleset()
  if (inRuleset?)
    @inRuleset = false

    puts "closeRuleset" unless (!$DEBUG)
    puts "" unless (!$DEBUG)
  end # if


end

#inGuideline?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/xmlutils/gdllistener.rb', line 49

def inGuideline?
  return @inGuideline
end

#inRule?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/xmlutils/gdllistener.rb', line 56

def inRule?
  return @inRule
end

#inRuleset?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/xmlutils/gdllistener.rb', line 63

def inRuleset?
  return @inRuleset
end

#openGuideline(attributes) ⇒ Object

————————————————————————————————————-# openGuideline - Add a Guideline to the context object

attributes - Guideline element attributes

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



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/xmlutils/gdllistener.rb', line 129

def openGuideline(attributes)
  return unless (!inGuideline?)

  if ($DEBUG)
    puts "openGuideline:"

    if(!attributes.empty?)
      puts "      Attr:"
      attributes.each do |attr|
        puts "            #{attr[0]}: #{attr[1]}"
      end
    end
  end # if $DEBUG


  @gdl = Guideline.new(attributes)

  @inGuideline = true

end

#openRule(attributes) ⇒ Object

————————————————————————————————————-# openRule - Add a rule to the context object

attributes - rule element attributes

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



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/xmlutils/gdllistener.rb', line 175

def openRule(attributes)
  return unless (inGuideline? && (!inRuleset?))

  if ($DEBUG)
    puts "openRule:"

    if(!attributes.empty?)
      puts "      Attr:"
      attributes.each do |attr|
        puts "            #{attr[0]}: #{attr[1]}"
      end
    end
  end # if $DEBUG


  ruleAlias = attributes["Name"]
  item      = ["rule", "#{ruleAlias}"]

  @gdl.addItem(item)
  @inRule = true

  puts "Guideline item: [#{item[0]}] #{item[1]}" if verbose?

end

#openRuleset(attributes) ⇒ Object

————————————————————————————————————-# openRuleset - Open a ruleset object

attributes - ruleset element attributes

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



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/xmlutils/gdllistener.rb', line 224

def openRuleset(attributes)
  return unless (inGuideline? && (!inRuleset?))

  if ($DEBUG)
    puts "openRuleset:"

    if(!attributes.empty?)
      puts "      Attr:"
      attributes.each do |attr|
        puts "            #{attr[0]}: #{attr[1]}"
      end
    end
  end # if $DEBUG


  rsAlias   = attributes["Name"]
  item      = ["ruleset", "#{rsAlias}"]

  @gdl.addItem(item)
  @inRuleset  = true

  puts "Guideline item: [#{item[0]}] #{item[1]}" if verbose?

end

#tag_end(tag) ⇒ Object

————————————————————————————————————-# tag_end - An ending tag has been parsed

tag - name of tag (element name) ————————————————————————————————————#



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/xmlutils/gdllistener.rb', line 102

def tag_end(tag)

  case tag
    when 'Guideline'
      closeGuideline()

    when 'Rule'
      closeRule()

    when 'Ruleset'
      closeRuleset()

    else
      closeUnknown(tag)                 # Don't care

  end # case


end

#tag_start(tag, attributes) ⇒ Object

————————————————————————————————————-# tag_start - A start tag has been parsed

tag - name of tag (element name) attributes - element tag attributes ————————————————————————————————————#



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/xmlutils/gdllistener.rb', line 76

def tag_start(tag, attributes)

  case tag
    when 'Guideline'
      openGuideline(attributes)

    when 'Rule'
      openRule(attributes)

    when 'Ruleset'
      openRuleset(attributes)

    else
      openUnknown(tag, attributes)        # Don't care

  end # case


end