Module: Doc2Text::Odt::XmlNodes::Node
- Included in:
- Generic, Office::AutomaticStyles, Office::DocumentContent, Office::Text, PlainText, Style::Style, Style::TextProperties, Table::TableCell, Table::TableRow, Text::LineBreak, Text::List, Text::ListItem, Text::P, Text::Span
- Defined in:
- lib/doc2text/odt_xml_node.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
- .create_node(prefix, name, parent = nil, attrs = [], markdown_odt_parser = nil) ⇒ Object
- .included(base) ⇒ Object
- .titleize(tag) ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
- #delete ⇒ Object
- #eql?(object) ⇒ Boolean
- #expand ⇒ Object
- #generic? ⇒ Boolean
- #has_text? ⇒ Boolean
- #initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_odt_parser = nil) ⇒ Object
- #not_enclosing? ⇒ Boolean
- #office_text? ⇒ Boolean
- #open ⇒ Object
- #root? ⇒ Boolean
- #to_s ⇒ Object
- #xml_name ⇒ Object
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
5 6 7 |
# File 'lib/doc2text/odt_xml_node.rb', line 5 def attrs @attrs end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lib/doc2text/odt_xml_node.rb', line 5 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/doc2text/odt_xml_node.rb', line 5 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/doc2text/odt_xml_node.rb', line 5 def parent @parent end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/doc2text/odt_xml_node.rb', line 5 def prefix @prefix end |
#text ⇒ Object
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
#close ⇒ Object
41 42 43 |
# File 'lib/doc2text/odt_xml_node.rb', line 41 def close '' end |
#delete ⇒ Object
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
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 |
#expand ⇒ Object
72 73 74 75 76 |
# File 'lib/doc2text/odt_xml_node.rb', line 72 def = "#{open}#{@children.map(&:expand).join}#{close}" delete .clone end |
#generic? ⇒ Boolean
60 61 62 |
# File 'lib/doc2text/odt_xml_node.rb', line 60 def generic? instance_of? Node end |
#has_text? ⇒ 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
78 79 80 81 82 |
# File 'lib/doc2text/odt_xml_node.rb', line 78 def not_enclosing? !root? && parent.class. && parent.class..find do |tag| @prefix == parent.prefix && @name == tag end end |
#office_text? ⇒ Boolean
45 46 47 |
# File 'lib/doc2text/odt_xml_node.rb', line 45 def office_text? false end |
#open ⇒ Object
37 38 39 |
# File 'lib/doc2text/odt_xml_node.rb', line 37 def open '' end |
#root? ⇒ Boolean
29 30 31 |
# File 'lib/doc2text/odt_xml_node.rb', line 29 def root? !@parent end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/doc2text/odt_xml_node.rb', line 68 def to_s "#{xml_name} : #{attrs}" end |
#xml_name ⇒ Object
64 65 66 |
# File 'lib/doc2text/odt_xml_node.rb', line 64 def xml_name "#{@prefix}:#{@name}" end |