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
- #delete_on_close? ⇒ Boolean
- #eql?(object) ⇒ Boolean
- #expand ⇒ Object
- #generic? ⇒ Boolean
- #has_text? ⇒ Boolean
- #initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_odt_parser = nil) ⇒ Object
- #not_deleted? ⇒ Boolean
- #not_enclosing? ⇒ Boolean
- #open ⇒ Object
- #root? ⇒ Boolean
- #to_s ⇒ Object
- #un_delete ⇒ 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
92 93 94 |
# File 'lib/doc2text/odt_xml_node.rb', line 92 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
53 54 55 56 57 |
# File 'lib/doc2text/odt_xml_node.rb', line 53 def delete @deleted = true # @children.each { |child| child.delete } # @children = [] end |
#delete_on_close? ⇒ Boolean
45 46 47 |
# File 'lib/doc2text/odt_xml_node.rb', line 45 def delete_on_close? false end |
#eql?(object) ⇒ Boolean
63 64 65 66 |
# File 'lib/doc2text/odt_xml_node.rb', line 63 def eql?(object) return false unless object.is_a? Node object.xml_name == xml_name end |
#expand ⇒ Object
80 81 82 83 84 |
# File 'lib/doc2text/odt_xml_node.rb', line 80 def = "#{open}#{@children.select(&:not_deleted?).map(&:expand).join}#{close}" delete .clone end |
#generic? ⇒ Boolean
68 69 70 |
# File 'lib/doc2text/odt_xml_node.rb', line 68 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_deleted? ⇒ Boolean
49 50 51 |
# File 'lib/doc2text/odt_xml_node.rb', line 49 def not_deleted? !@deleted end |
#not_enclosing? ⇒ Boolean
86 87 88 89 90 |
# File 'lib/doc2text/odt_xml_node.rb', line 86 def not_enclosing? !root? && parent.class. && parent.class..find do |tag| @prefix == parent.prefix && @name == tag end 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
76 77 78 |
# File 'lib/doc2text/odt_xml_node.rb', line 76 def to_s "#{xml_name} : #{attrs}" end |
#un_delete ⇒ Object
59 60 61 |
# File 'lib/doc2text/odt_xml_node.rb', line 59 def un_delete @deleted = false end |
#xml_name ⇒ Object
72 73 74 |
# File 'lib/doc2text/odt_xml_node.rb', line 72 def xml_name "#{@prefix}:#{@name}" end |