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

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

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



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

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

.included(base) ⇒ Object



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

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

.titleize(tag) ⇒ Object



19
20
21
# File 'lib/doc2text/odt_xml_node.rb', line 19

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

Instance Method Details

#closeObject



41
42
43
# File 'lib/doc2text/odt_xml_node.rb', line 41

def close
  ''
end

#deleteObject



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

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

#eql?(object) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#expandObject



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

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

#generic?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/doc2text/odt_xml_node.rb', line 60

def generic?
  instance_of? Node
end

#has_text?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/doc2text/odt_xml_node.rb', line 33

def has_text?
  @has_text
end

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



23
24
25
26
27
# File 'lib/doc2text/odt_xml_node.rb', line 23

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

#not_enclosing?Boolean

Returns:

  • (Boolean)


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

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

#office_text?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/doc2text/odt_xml_node.rb', line 45

def office_text?
  false
end

#openObject



37
38
39
# File 'lib/doc2text/odt_xml_node.rb', line 37

def open
  ''
end

#root?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/doc2text/odt_xml_node.rb', line 29

def root?
  !@parent
end

#to_sObject



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

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

#xml_nameObject



64
65
66
# File 'lib/doc2text/odt_xml_node.rb', line 64

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