Class: Riddl::Wrapper::Description::HashBase

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

Direct Known Subclasses

Message, Transformation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layer, name, type, content = nil) ⇒ HashBase

{{{



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 7

def initialize(layer,name,type,content=nil)
  @name = name
  @hash = nil
  if layer.nil?
    @content = content
  else
    @content = layer.find("des:#{type}[@name='#{name}']").first.to_doc
    @content.root.find("@name").delete_all!
    @content.register_namespace 'des', Riddl::Wrapper::DESCRIPTION
  end
  update_hash!
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



50
51
52
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 50

def content
  @content
end

#hashObject (readonly)

Returns the value of attribute hash.



50
51
52
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 50

def hash
  @hash
end

#hash_baseObject (readonly)

Returns the value of attribute hash_base.



50
51
52
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 50

def hash_base
  @hash_base
end

#nameObject (readonly)

Returns the value of attribute name.



50
51
52
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 50

def name
  @name
end

Instance Method Details

#traverse?(other) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 34

def traverse?(other)
  if other.name.nil?
    false
  else
    paths = self.hash_base.find("//des:parameter").map{ |e| e.path + "/@name" }
    hb2 = XML::Smart::string(other.hash_base.serialize)
    hb2.register_namespace 'des', Riddl::Wrapper::DESCRIPTION
    hb2.unformated = true

    paths.each do |p|
      (hb2.find(p).first.value = '*') rescue nil
    end

    self.hash_base.serialize.hash == hb2.serialize.hash
  end
end

#update_hash!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby/riddl/wrapper/description/message_and_transformation.rb', line 19

def update_hash!
  # TODO too simple
  hb = @content.root.to_doc
  hb.register_namespace 'des', Riddl::Wrapper::DESCRIPTION
  hb.unformated = true
  hb.find("//comment()").delete_all!
  hb.find("//des:parameter/*").delete_all!
  hb.find("//text()").delete_all!
  hb.find("//des:header/*").delete_all!
  hb.find("//des:parameter/@handler").delete_all!
  # hb.find("//des:parameter/@mimetype").each { |e| e.value = '' }
  hb.root.namespaces.delete_all!
  @hash_base = hb
  @hash      = hb.serialize.hash
end