Class: Plurimath::XmlEngine::OxEngine::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/xml_engine/ox_engine/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_engine/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_engine/element.rb', line 5

def attributes
  @attributes
end

Instance Method Details

#<<(object) ⇒ Object



41
42
43
44
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 41

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_engine/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_engine/element.rb', line 17

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

#[]=(attr, value) ⇒ Object



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

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

#each(&block) ⇒ Object



63
64
65
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 63

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

#insert_in_nodes(index, element) ⇒ Object



75
76
77
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 75

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

#is_xml_comment?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 89

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

#locate(string) ⇒ Object



79
80
81
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 79

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

#map(&block) ⇒ Object



67
68
69
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 67

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

#nameObject



25
26
27
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 25

def name
  @node.name
end

#name=(new_name) ⇒ Object



29
30
31
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 29

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

#nodesObject



59
60
61
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 59

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

#remove_attr(attribute) ⇒ Object



37
38
39
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 37

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

#replace_nodes(nodes_array) ⇒ Object



83
84
85
86
87
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 83

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



33
34
35
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 33

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

#xml_node?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 71

def xml_node?
  true
end

#xml_nodesObject



55
56
57
# File 'lib/plurimath/xml_engine/ox_engine/element.rb', line 55

def xml_nodes
  @node
end