class Riddl::Wrapper::Description::Message

Public Class Methods

new(layer,name) click to toggle source

{{{

# File lib/ruby/riddl/wrapper/description/message_and_transformation.rb, line 67
def initialize(layer,name)
  super layer,name,:message
end

Public Instance Methods

initialize_copy(o) click to toggle source
# File lib/ruby/riddl/wrapper/description/message_and_transformation.rb, line 70
def initialize_copy(o)
  @content = @content.dup
end
transform(trans) click to toggle source
# 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