Class: SistemKebut::XML::Element

Inherits:
Object
  • Object
show all
Includes:
Peralatan::RemoteSistem
Defined in:
lib/xml/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Peralatan::RemoteSistem

#_t

Constructor Details

#initialize(tag, *args) ⇒ Element

Returns a new instance of Element.



64
65
66
67
68
69
70
# File 'lib/xml/builder.rb', line 64

def initialize(tag, *args)
  @tag = tag
  @konten = []
  @namespace = nil
  @deep_namespace = nil
  @keterangan = args.collect { |i| urai(i) } .compact
end

Instance Attribute Details

#deep_namespaceObject (readonly)

Returns the value of attribute deep_namespace.



63
64
65
# File 'lib/xml/builder.rb', line 63

def deep_namespace
  @deep_namespace
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



63
64
65
# File 'lib/xml/builder.rb', line 63

def namespace
  @namespace
end

Instance Method Details

#append(elm) ⇒ Object



72
73
74
75
# File 'lib/xml/builder.rb', line 72

def append(elm)
  @konten.push(elm)
  return nil
end

#childObject



77
78
79
# File 'lib/xml/builder.rb', line 77

def child
  @konten.length == 1 ? @konten.first : nil
end

#serialize(nokoxml, warisan = nil) ⇒ Object



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
# File 'lib/xml/builder.rb', line 81

def serialize(nokoxml, warisan=nil)
  proses = proc { |i| i.is_a?(Hash) && i.has_key?(:_konten) }
  dalam = @konten.select(&proses)
  val = dalam.collect { |i| i[:_konten] } .join
  @keterangan.delete_if do |i|
    if i.is_a?(String)
      val.concat(i)
      next true
    end
  end
  atribut = @keterangan.collect do |kumpulan|
    hasil = {}
    kumpulan.each_key do |ns|
      case ns
      when 'xmlns'
        hasil['xmlns'] = kumpulan['xmlns']
      when 'Ignorable'
        hasil['mc:Ignorable'] = kumpulan['Ignorable']
      when /^(?:pic|a|o|r|v|w|w10|wp|wps|wpg|mc|wp14|w14|w15)$/
        hasil["xmlns:#{ns}"] = kumpulan[ns]
      else
        hasil[ns] = kumpulan[ns]
      end
    end
    hasil
  end
  if @tag == :p
    nokoxml.p do 
      @konten.each do |i|
        next if dalam.include?(i)
        i.serialize(nokoxml)
      end
    end
  else
    ns = @namespace
    ns = @deep_namespace if ns.nil?
    ns = warisan if ns.nil?
    elm = nokoxml.send(@tag, *atribut, val) do 
      @konten.each do |i|
        next if dalam.include?(i)
        pewarisan = @deep_namespace
        pewarisan = warisan if pewarisan.nil?
        i.serialize(nokoxml, pewarisan)
      end
    end
    unless ns.nil?
      elm['skripsi-namespace'] = ns
    end
  end
end