Class: Riddl::Wrapper::MessageParser
- Inherits:
-
Object
- Object
- Riddl::Wrapper::MessageParser
- Defined in:
- lib/ruby/riddl/wrapper/messageparser.rb
Instance Method Summary collapse
- #check(what, ignore_name = false) ⇒ Object
- #choice(a) ⇒ Object
- #group(a) ⇒ Object
-
#initialize(params, headers) ⇒ MessageParser
constructor
A new instance of MessageParser.
- #oneOrMore(a) ⇒ Object
- #optional(a) ⇒ Object
- #traverse_simple(a, single_optional_protection = false) ⇒ Object
- #zeroOrMore(a) ⇒ Object
Constructor Details
#initialize(params, headers) ⇒ MessageParser
Returns a new instance of MessageParser.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 4 def initialize(params,headers) #{{{ @mist = params @mistp = 0 @headp = {} headers.each do |k,v| if v.nil? @headp[k.name.upcase.gsub(/\-/,'_')] = k.value else @headp[k.upcase.gsub(/\-/,'_')] = v end end @numparams = 0 #}}} end |
Instance Method Details
#check(what, ignore_name = false) ⇒ Object
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 46 47 48 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 21 def check(what,ignore_name=false) #{{{ # reset for subsequent calls @mistp = 0 @numparams = 0 # out not available return true if what.nil? && @mist.empty? # do it m = what.content.root m.find("des:header").each do |h| return false unless header h end if ignore_name # if only one parameter, ignore the name @numparams = m.find("count(//des:parameter)").to_i end m.find("des:*[not(name()='header')]").each do |p| return false unless send p.qname.to_s, p end @mist.count == @mistp #}}} end |
#choice(a) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 114 def choice(a) #{{{ a.find("des:*").each do |p| return true if send p.qname.to_s, p end false #}}} end |
#group(a) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 123 def group(a) #{{{ tistp = @mistp success = true a.find("des:*").each do |p| unless send p.qname.to_s, p success = false break end end if success true else @mistp = tistp false end #}}} end |
#oneOrMore(a) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 88 def oneOrMore(a) #{{{ tistp = @mistp ncounter = 0 begin counter,length = traverse_simple(a,true) ncounter += 1 if counter == length end while counter == length && @mistp < @mist.length if ncounter > 0 true else @mistp = tistp false end #}}} end |
#optional(a) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 142 def optional(a) #{{{ return true if @mistp >= @mist.length tistp = @mistp counter, length = traverse_simple(a,true) if counter == 0 || counter == length true else @mistp = tistp false end #}}} end |
#traverse_simple(a, single_optional_protection = false) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 169 def traverse_simple(a,single_optional_protection=false) #{{{ tistp = @mistp nodes = a.find("des:*") counter = 0 lastname = '' nodes.each do |p| lastname = p.qname.to_s counter += 1 if send lastname, p end if single_optional_protection && lastname == 'optional' && tistp == @mistp [0,-1] else [counter,nodes.length] end #}}} end |
#zeroOrMore(a) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 105 def zeroOrMore(a) #{{{ begin counter,length = traverse_simple(a,true) end while counter == length && @mistp < @mist.length true #}}} end |