Class: RuleParser

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

Overview

class RuleParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ RuleParser

————————————————————————————————————-# initialize - Constructor

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



28
29
30
31
32
# File 'lib/xmlutils/ruleparser.rb', line 28

def initialize(ctx)
  @verbose    = false
  @context    = ctx

end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



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

def context
  @context
end

Instance Method Details

#parse(src) ⇒ Object

————————————————————————————————————-# parse - Build a GDL rule definition from XML source.

src - String containing XML source gdl - GDL rule definition.

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



79
80
81
82
83
84
85
86
# File 'lib/xmlutils/ruleparser.rb', line 79

def parse(src)
  doc = nil
  doc = Document.new(src)
  root = doc.root

  return parseRuleXml(root)

end

#parseRuleXml(rule) ⇒ Object

————————————————————————————————————-# parseRuleXml - generate a GDL version of a rule definition based on Rule XML element

rule - XML element to generate output for

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



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/xmlutils/ruleparser.rb', line 99

def parseRuleXml(rule)
#   arule = root.elements['//Rule'].to_a  # returns all 1st level rule children elements
  #ruleParts = rule.elements.to_a
  puts "Parsing rule: #{rule.attributes['Name']}" if verbose?

  visitor = XmlRuleVisitor.new(@context)
  output = ""

  return visitor.visit(rule, output)


end

#setFlag(flg) ⇒ Object

————————————————————————————————————-# setFlag - Set configuration flags

flg - Array of options or single string option. Currently, only -v: verbose is available

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xmlutils/ruleparser.rb', line 50

def setFlag(flg)
  if (flg.class == Array)
    flg.each do |f|
      case f
        when '-v'
          @verbose = true
      end
    end # flg.each

    return
  end # if flg

  case flg
    when '-v'
      @verbose = true
  end

end

#verbose?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/xmlutils/ruleparser.rb', line 37

def verbose?
  @verbose
end