Module: Doc2Text::Odt::XmlNodes::Node

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



5
6
7
# File 'lib/doc2text/odt_xml_node.rb', line 5

def attrs
  @attrs
end

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/doc2text/odt_xml_node.rb', line 5

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/doc2text/odt_xml_node.rb', line 5

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/doc2text/odt_xml_node.rb', line 5

def parent
  @parent
end

#prefixObject (readonly)

Returns the value of attribute prefix.



5
6
7
# File 'lib/doc2text/odt_xml_node.rb', line 5

def prefix
  @prefix
end

Class Method Details

.create_node(prefix, name, parent = nil, attrs = [], markdown_document = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/doc2text/odt_xml_node.rb', line 7

def self.create_node(prefix, name, parent = nil, attrs = [], markdown_document = nil)
  begin
    clazz = XmlNodes.const_get "#{titleize prefix}::#{titleize name}"
  rescue NameError => e
    Generic.new(parent, attrs, prefix, name, markdown_document)
  else
    clazz.new(parent, attrs, prefix, name, markdown_document)
  end
end

.included(base) ⇒ Object



83
84
85
# File 'lib/doc2text/odt_xml_node.rb', line 83

def self.included(base)
  base.extend ClassMethods
end

.titleize(tag) ⇒ Object



17
18
19
# File 'lib/doc2text/odt_xml_node.rb', line 17

def self.titleize(tag)
  tag.split('-').map(&:capitalize).join
end

Instance Method Details

#<<(child) ⇒ Object



43
44
45
# File 'lib/doc2text/odt_xml_node.rb', line 43

def <<(child)
  @children << child
end

#closeObject



39
40
41
# File 'lib/doc2text/odt_xml_node.rb', line 39

def close
  ''
end

#delete_on_close?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/doc2text/odt_xml_node.rb', line 47

def delete_on_close?
  true
end

#eql?(object) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/doc2text/odt_xml_node.rb', line 51

def eql?(object)
  return false unless object.is_a? Node
  object.xml_name == xml_name
end

#generic?Boolean

Returns:

  • (Boolean)


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

def generic?
  instance_of? Node
end

#has_text?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/doc2text/odt_xml_node.rb', line 31

def has_text?
  @has_text
end

#initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_document = nil) ⇒ Object



21
22
23
24
25
# File 'lib/doc2text/odt_xml_node.rb', line 21

def initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_document = nil)
  @parent, @attrs, @prefix, @name = parent, attrs, prefix, name
  @children = []
  @has_text = false
end

#not_enclosing?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/doc2text/odt_xml_node.rb', line 77

def not_enclosing?
  !root? && parent.class.not_enclosing_tags && parent.class.not_enclosing_tags.find do |tag|
    @prefix == parent.prefix && @name == tag
  end
end

#openObject



35
36
37
# File 'lib/doc2text/odt_xml_node.rb', line 35

def open
  ''
end

#remove_last_child!(child) ⇒ Object



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

def remove_last_child!(child)
  unless child === @children.last
    # TODO remove this redundant(tree build algorithm) checks
    raise Doc2Text::XmlError, "!The child #{child} IS NOT among the children of #{self}"
  else
    @children.pop
  end
end

#root?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/doc2text/odt_xml_node.rb', line 27

def root?
  !@parent
end

#to_sObject



73
74
75
# File 'lib/doc2text/odt_xml_node.rb', line 73

def to_s
  "#{xml_name} : #{attrs}"
end

#xml_nameObject



69
70
71
# File 'lib/doc2text/odt_xml_node.rb', line 69

def xml_name
  "#{@prefix}:#{@name}"
end