Class: Riddl::Wrapper::MessageParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/wrapper/messageparser.rb

Instance Method Summary collapse

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
49
# 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?
  return false if what.nil?

  # 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



115
116
117
118
119
120
121
122
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 115

def choice(a)
  #{{{
  a.find("des:*").each do |p|
    return true if send p.qname.to_s, p
  end
  false
  #}}}
end

#group(a) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 124

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 89

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



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 143

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



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 170

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



106
107
108
109
110
111
112
113
# File 'lib/ruby/riddl/wrapper/messageparser.rb', line 106

def zeroOrMore(a)
  #{{{
  begin
    counter,length = traverse_simple(a,true)
  end while counter == length && @mistp < @mist.length
  true
  #}}}
end