Class: RubyDocx::Elements::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_docx/elements/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, node) ⇒ Element

Returns a new instance of Element.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby_docx/elements/element.rb', line 8

def initialize(doc, node)
  @node = node
  @doc = doc

  if self.node.name.to_s == "pict"
    @doc.setup_image(self)
  elsif self.node.name.to_s == "drawing"
    @doc.setup_drawing(self)
  elsif self.node.name.to_s == "object"
    @doc.setup_object(self)
  end

  self.parse_elements
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



5
6
7
# File 'lib/ruby_docx/elements/element.rb', line 5

def doc
  @doc
end

#gridObject (readonly)

Returns the value of attribute grid.



5
6
7
# File 'lib/ruby_docx/elements/element.rb', line 5

def grid
  @grid
end

#nodeObject (readonly)

Returns the value of attribute node.



5
6
7
# File 'lib/ruby_docx/elements/element.rb', line 5

def node
  @node
end

#styleObject (readonly)

Returns the value of attribute style.



5
6
7
# File 'lib/ruby_docx/elements/element.rb', line 5

def style
  @style
end

Instance Method Details

#elementsObject Also known as: parse_elements



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_docx/elements/element.rb', line 31

def elements
  @elements ||= @node.children.map do |c_node|
    v = RubyDocx::Elements::Parser.parse_by_name(@doc, c_node)

    if ["pPr", "rPr", "tblPr", "tcPr"].index(c_node.name.to_s)
      @style = v
      nil
    elsif ["tblGrid"].index(c_node.name.to_s)
      @grid = v
      nil
    else
      v
    end
  end.compact
end

#inspectObject



49
50
51
# File 'lib/ruby_docx/elements/element.rb', line 49

def inspect
  "#<#{self.class} @node=#{@node.name}>"
end

#to_sObject



23
24
25
# File 'lib/ruby_docx/elements/element.rb', line 23

def to_s
  @node.to_s
end

#to_xmlObject



27
28
29
# File 'lib/ruby_docx/elements/element.rb', line 27

def to_xml
  @node.to_s
end