Class: Doc2Text::XmlBasedDocument::XmlNodes::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/doc2text/generic_xml_nodes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_odt_parser = nil) ⇒ Node

Returns a new instance of Node.



14
15
16
17
18
# File 'lib/doc2text/generic_xml_nodes.rb', line 14

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

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



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

def attrs
  @attrs
end

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/doc2text/generic_xml_nodes.rb', line 6

def text
  @text
end

Class Method Details

.inherited(subclass) ⇒ Object



8
9
10
11
12
# File 'lib/doc2text/generic_xml_nodes.rb', line 8

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

Instance Method Details

#closeObject



32
33
34
# File 'lib/doc2text/generic_xml_nodes.rb', line 32

def close
  ''
end

#deleteObject



36
37
38
39
40
# File 'lib/doc2text/generic_xml_nodes.rb', line 36

def delete
  return true unless @children
  @children.each { |child| child.delete }
  @children = []
end

#eql?(object) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#expandObject



59
60
61
62
63
# File 'lib/doc2text/generic_xml_nodes.rb', line 59

def expand
  expanded = "#{open}#{@children.map(&:expand).join}#{close}"
  delete
  expanded.clone
end

#generic?Boolean

Returns:

  • (Boolean)


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

def generic?
  instance_of? Node
end

#has_text?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/doc2text/generic_xml_nodes.rb', line 24

def has_text?
  @has_text
end

#openObject



28
29
30
# File 'lib/doc2text/generic_xml_nodes.rb', line 28

def open
  ''
end

#root?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/doc2text/generic_xml_nodes.rb', line 20

def root?
  !@parent
end

#to_sObject



55
56
57
# File 'lib/doc2text/generic_xml_nodes.rb', line 55

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

#xml_nameObject



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

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