Class: Riddl::Wrapper::Description::Message

Inherits:
HashBase
  • Object
show all
Defined in:
lib/ruby/riddl/wrapper/description/message_and_transformation.rb

Instance Attribute Summary

Attributes inherited from HashBase

#content, #hash, #hash_base, #name

Instance Method Summary collapse

Methods inherited from HashBase

#traverse?, #update_hash!

Constructor Details

#initialize(layer, name) ⇒ Message

{{{



67
68
69
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 67

def initialize(layer,name)
  super layer,name,:message
end

Instance Method Details

#initialize_copy(o) ⇒ Object



70
71
72
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 70

def initialize_copy(o)
  @content = @content.dup
end

#transform(trans) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 73

def transform(trans)
  ret = self.dup
  unless trans.name.nil?
    trans.content.root.children.each do |e|
      case e.qname.name
        when 'add_header'
          raise "TODO"
        when 'add_before'
          raise "TODO"
        when 'add_after'
          raise "TODO"
        when 'add_as_first'
          t = ret.content.root
          n = t.find("header[last()]").first
          if n.nil?
            m = t.find("*[not(header)]").first
            if m.nil?
              t.add(e.children)
            else
              m.add_before(e.children)
            end
          else
            n.add_after(e.children)
          end
        when 'add_as_last'
          ret.content.root.add(e.children)
          ret.update_hash!
        when 'remove_each'
          ret.content.find("parameter[@name=\"#{e.attributes['name']}\"]").delete_all!
        when 'remove_first'
          if e.attributes['name']
            case e.attributes['type']
              when 'parameter', nil
                node = ret.content.find("//parameter[@name=\"#{e.attributes['name']}\"]").first
                opt = node.add_before("optional")
                opt.add(node)
              when 'header'
                ret.content.find("header[@name=\"#{e.attributes['name']}\"]").delete_all!
            end
          else
            case e.attributes['type']
              when 'parameter', nil
                ret.content.find("//parameter[first()]").delete_all!
              when 'header'
                ret.content.find("//header[first()]").delete_all!
            end
          end
        when 'remove_last'
          if e.attributes['name']
            case e.attributes['type']
              when 'parameter', nil
                node = ret.content.find("//parameter[@name=\"#{e.attributes['name']}\"]").last
                opt = node.add_before("optional")
                opt.add(node)
              when 'header'
                ret.content.find("header[@name=\"#{e.attributes['name']}\"]").delete_all!
            end
          else
            case e.attributes['type']
              when 'parameter', nil
                ret.content.find("//parameter[last()]").delete_all!
              when 'header'
                ret.content.find("//header[last()]").delete_all!
            end
          end
      end
    end
  end
  return ret
end