Class: Plurimath::XmlEngine::Ox::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/xml_engine/ox/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Element

Returns a new instance of Element.



7
8
9
# File 'lib/plurimath/xml_engine/ox/element.rb', line 7

def initialize(node)
  @node = node.is_a?(String) ? ::Ox::Element.new(node) : node
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/plurimath/xml_engine/ox/element.rb', line 5

def attributes
  @attributes
end

Instance Method Details

#<<(object) ⇒ Object



43
44
45
46
# File 'lib/plurimath/xml_engine/ox/element.rb', line 43

def <<(object)
  @node << (object.is_a?(String) ? object : object.xml_nodes)
  self
end

#==(object) ⇒ Object



11
12
13
14
15
# File 'lib/plurimath/xml_engine/ox/element.rb', line 11

def ==(object)
  self.class == object.class &&
    @node == object.xml_nodes &&
    nodes == object.nodes
end

#[](object) ⇒ Object



17
18
19
# File 'lib/plurimath/xml_engine/ox/element.rb', line 17

def [](object)
  xml_nodes&.attributes&.dig(object.to_s)
end

#[]=(attr, value) ⇒ Object



21
22
23
24
# File 'lib/plurimath/xml_engine/ox/element.rb', line 21

def []=(attr, value)
  update_attrs(@node, { attr.to_s => value.to_s })
  update_attrs(self, { attr.to_s => value.to_s })
end

#each(&block) ⇒ Object



65
66
67
# File 'lib/plurimath/xml_engine/ox/element.rb', line 65

def each(&block)
  xml_nodes.each(&block)
end

#insert_in_nodes(index, element) ⇒ Object



77
78
79
# File 'lib/plurimath/xml_engine/ox/element.rb', line 77

def insert_in_nodes(index, element)
  @node.nodes.insert(index, element.xml_nodes)
end

#is_xml_comment?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/plurimath/xml_engine/ox/element.rb', line 91

def is_xml_comment?
  xml_nodes.is_a?(::Ox::Comment)
end

#locate(string) ⇒ Object



81
82
83
# File 'lib/plurimath/xml_engine/ox/element.rb', line 81

def locate(string)
  @node.locate(string)
end

#map(&block) ⇒ Object



69
70
71
# File 'lib/plurimath/xml_engine/ox/element.rb', line 69

def map(&block)
  xml_nodes.map(&block)
end

#nameObject



26
27
28
# File 'lib/plurimath/xml_engine/ox/element.rb', line 26

def name
  @node.name
end

#name=(new_name) ⇒ Object



30
31
32
# File 'lib/plurimath/xml_engine/ox/element.rb', line 30

def name=(new_name)
  @node.name = new_name
end

#nodesObject



61
62
63
# File 'lib/plurimath/xml_engine/ox/element.rb', line 61

def nodes
  xml_nodes.nodes.map { |node| element_or_string(node) }
end

#remove_attr(attribute) ⇒ Object



39
40
41
# File 'lib/plurimath/xml_engine/ox/element.rb', line 39

def remove_attr(attribute)
  xml_nodes&.attributes&.delete(attribute)
end

#replace_nodes(nodes_array) ⇒ Object



85
86
87
88
89
# File 'lib/plurimath/xml_engine/ox/element.rb', line 85

def replace_nodes(nodes_array)
  xml_nodes.nodes.replace(
    nodes_array.all?(Element) ? nodes_array.map(&:xml_nodes) : nodes_array
  )
end

#set_attr(attrs) ⇒ Object



34
35
36
37
# File 'lib/plurimath/xml_engine/ox/element.rb', line 34

def set_attr(attrs)
  update_attrs(@node, attrs)
  update_attrs(self, attrs)
end

#xml_node?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/plurimath/xml_engine/ox/element.rb', line 73

def xml_node?
  true
end

#xml_nodesObject



57
58
59
# File 'lib/plurimath/xml_engine/ox/element.rb', line 57

def xml_nodes
  @node
end