Module: Doc2Text::Odt::XmlNodes::Node
- Included in:
- Generic, Office::AutomaticStyles, Office::DocumentContent, Style::Style, Style::TextProperties, Text::LineBreak, 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.
Class Method Summary collapse
- .create_node(prefix, name, parent = nil, attrs = [], markdown_document = nil) ⇒ Object
- .included(base) ⇒ Object
- .titleize(tag) ⇒ Object
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #close ⇒ Object
- #delete_on_close? ⇒ Boolean
- #eql?(object) ⇒ Boolean
- #generic? ⇒ Boolean
- #has_text? ⇒ Boolean
- #initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_document = nil) ⇒ Object
- #not_enclosing? ⇒ Boolean
- #open ⇒ Object
- #remove_last_child!(child) ⇒ 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 |
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 |
#close ⇒ Object
39 40 41 |
# File 'lib/doc2text/odt_xml_node.rb', line 39 def close '' end |
#delete_on_close? ⇒ Boolean
47 48 49 |
# File 'lib/doc2text/odt_xml_node.rb', line 47 def delete_on_close? true end |
#eql?(object) ⇒ 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
56 57 58 |
# File 'lib/doc2text/odt_xml_node.rb', line 56 def generic? instance_of? Node end |
#has_text? ⇒ 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
77 78 79 80 81 |
# File 'lib/doc2text/odt_xml_node.rb', line 77 def not_enclosing? !root? && parent.class. && parent.class..find do |tag| @prefix == parent.prefix && @name == tag end end |
#open ⇒ Object
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
27 28 29 |
# File 'lib/doc2text/odt_xml_node.rb', line 27 def root? !@parent end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/doc2text/odt_xml_node.rb', line 73 def to_s "#{xml_name} : #{attrs}" end |
#xml_name ⇒ Object
69 70 71 |
# File 'lib/doc2text/odt_xml_node.rb', line 69 def xml_name "#{@prefix}:#{@name}" end |