Class: Rubyword::Element::Paragraph

Inherits:
Text
  • Object
show all
Defined in:
lib/rubyword/element/paragraph.rb

Constant Summary

Constants inherited from Text

Text::IndentSize

Instance Attribute Summary collapse

Attributes inherited from Text

#texts

Attributes inherited from Base

#rubyword, #section

Instance Method Summary collapse

Methods inherited from Text

#save, #write_normal

Methods inherited from Base

#filter_text

Constructor Details

#initialize(rubyword, section = nil, style) ⇒ Paragraph

Returns a new instance of Paragraph.



6
7
8
9
# File 'lib/rubyword/element/paragraph.rb', line 6

def initialize(rubyword, section=nil, style)
  super(rubyword, section)
  @style = style
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arg) ⇒ Object



33
34
35
# File 'lib/rubyword/element/paragraph.rb', line 33

def method_missing(name, *arg)
  @section.send(name.to_sym, *arg)
end

Instance Attribute Details

#paragraphsObject

Returns the value of attribute paragraphs.



5
6
7
# File 'lib/rubyword/element/paragraph.rb', line 5

def paragraphs
  @paragraphs
end

#styleObject

Returns the value of attribute style.



5
6
7
# File 'lib/rubyword/element/paragraph.rb', line 5

def style
  @style
end

Instance Method Details

#text(text, style = nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/rubyword/element/paragraph.rb', line 11

def text(text, style=nil)
  @paragraphs ||= []
  text = filter_text(text)
  @paragraphs << {
    text: text,
    style: style
  }
end

#write(section = nil, xml = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rubyword/element/paragraph.rb', line 20

def write(section=nil, xml=nil)
  @xml = xml
  @xml.send('w:p') { 
    @paragraphs.each do |p|
      Writer::Style::Paragraph.new(@section, @xml, @rubyword).write(p[:style])
      @xml.send('w:r') do
        Writer::Style::Word.new(@section, @xml, @rubyword).write(p[:style])
        @xml.send('w:t', {'xml:space' => 'preserve'}, p[:text])
      end
    end
  }
end