Class: Docx::Elements::Bookmark
- Inherits:
-
Object
- Object
- Docx::Elements::Bookmark
show all
- Includes:
- Element
- Defined in:
- lib/docx/elements/bookmark.rb
Constant Summary
collapse
- TAG =
'bookmarkStart'
Constants included
from Element
Element::DEFAULT_TAG
Instance Attribute Summary collapse
Attributes included from Element
#node
Instance Method Summary
collapse
Methods included from Element
#append_to, #copy, included, #insert_after, #insert_before, #parent, #parent_paragraph, #prepend_to
Constructor Details
#initialize(node) ⇒ Bookmark
Returns a new instance of Bookmark.
11
12
13
14
|
# File 'lib/docx/elements/bookmark.rb', line 11
def initialize(node)
@node = node
@name = @node['w:name']
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/docx/elements/bookmark.rb', line 7
def name
@name
end
|
Instance Method Details
#get_run_after ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/docx/elements/bookmark.rb', line 61
def get_run_after
if (r_node = @node.at_xpath("./following-sibling::w:r"))
Containers::TextRun.new(r_node)
else
new_r = Containers::TextRun.create_with(self)
new_r.insert_after(self)
new_r
end
end
|
#get_run_before ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/docx/elements/bookmark.rb', line 47
def get_run_before
if not (r_nodes = @node.xpath("./preceding-sibling::w:r")).empty?
r_node = r_nodes.last
Containers::TextRun.new(r_node)
else
new_r = Containers::TextRun.create_with(self)
new_r.insert_before(self)
new_r
end
end
|
#insert_multiple_lines(text_array) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/docx/elements/bookmark.rb', line 26
def insert_multiple_lines(text_array)
paragraphs = []
paragraph = self.parent_paragraph
paragraph.blank!
paragraphs << paragraph
for i in 0...(text_array.size - 1)
new_p = paragraphs[i].copy
new_p.insert_after(paragraphs[i])
paragraphs << new_p
end
paragraphs.each_index do |index|
paragraphs[index].text = text_array[index]
end
end
|
#insert_text_after(text) ⇒ Object
21
22
23
24
|
# File 'lib/docx/elements/bookmark.rb', line 21
def insert_text_after(text)
text_run = get_run_before
text_run.text = "#{text_run.text}#{text}"
end
|
#insert_text_before(text) ⇒ Object
16
17
18
19
|
# File 'lib/docx/elements/bookmark.rb', line 16
def insert_text_before(text)
text_run = get_run_after
text_run.text = "#{text}#{text_run.text}"
end
|