Class: RXaal::XaalElement

Inherits:
Object show all
Includes:
Serializable
Defined in:
lib/xaal_element.rb

Constant Summary collapse

@@default_id_num =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

#xaal_serialize

Constructor Details

#initialize(doc, id = nil, elem_ns = nil) ⇒ XaalElement

Returns a new instance of XaalElement.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xaal_element.rb', line 13

def initialize(doc, id=nil, elem_ns = nil)
  @refs = 0
  @attribs = Array.new
  if (elem_ns != nil)
    @ns = elem_ns
  else
    @ns = doc.namespaces.name_to_ns[""]
  end
  
  @doc = doc
  
  if id == nil
    klass = self.class
    
    id = klass.name_minus_mod + "_" + XaalElement.get_new_default_id.to_s
  end
  
  @id = id 
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



10
11
12
# File 'lib/xaal_element.rb', line 10

def doc
  @doc
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/xaal_element.rb', line 9

def id
  @id
end

#refsObject (readonly)

Returns the value of attribute refs.



8
9
10
# File 'lib/xaal_element.rb', line 8

def refs
  @refs
end

Class Method Details

.get_new_default_idObject



60
61
62
63
64
65
66
67
# File 'lib/xaal_element.rb', line 60

def self.get_new_default_id
  if @@default_id_num == 0
    @@default_id_num = 1
    return 0
  else
    return @@default_id_num += 1
  end
end

.modify_ref(curr_obj, new_obj) ⇒ Object

increments the ref count of new_obj and decrements the ref count of curr_obj



42
43
44
45
46
47
48
# File 'lib/xaal_element.rb', line 42

def self.modify_ref(curr_obj, new_obj)
  if (curr_obj != nil)
    curr_obj.rm_ref
  end
  
  new_obj.add_ref
end

Instance Method Details

#add_attribute(name, value, attrib_ns = ns) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/xaal_element.rb', line 33

def add_attribute(name, value, attrib_ns = ns)
  temp = Attribute.new
  temp.name = name
  temp.value = value
  temp.ns = attrib_ns
  @attribs.push(temp)
end

#add_refObject

increments self’s ref count by 1



56
57
58
# File 'lib/xaal_element.rb', line 56

def add_ref
  @refs +=1
end

#rm_refObject

decrements self’s ref count by 1



51
52
53
# File 'lib/xaal_element.rb', line 51

def rm_ref
  @refs -= 1
end

#superclass_serialize(element) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/xaal_element.rb', line 69

def superclass_serialize(element)
  element.attributes["id"] = @id
  
  if @ns != doc.namespaces.name_to_ns[""]
    element.name = @ns.prefix + ":" + element.name
  end
end