Class: Rubyword::Element::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyword/element/text.rb

Direct Known Subclasses

Paragraph

Constant Summary collapse

IndentSize =

Toc indent size

200

Instance Attribute Summary collapse

Attributes inherited from Base

#rubyword, #section

Instance Method Summary collapse

Methods inherited from Base

#filter_text, #initialize

Constructor Details

This class inherits a constructor from Rubyword::Element::Base

Instance Attribute Details

#textsObject

Returns the value of attribute texts.



4
5
6
# File 'lib/rubyword/element/text.rb', line 4

def texts
  @texts
end

Instance Method Details

#save(text, type = nil, style = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubyword/element/text.rb', line 8

def save(text, type=nil, style=nil)
  @texts ||= Queue.new
  @section.titles ||= []
  return if text.nil? || type.nil?
  text = filter_text(text)
  if type == 'text'
    text(text, style)
  else
    self.send(type.to_sym, text, style)
  end
end

#text(text, style) ⇒ Object



20
21
22
# File 'lib/rubyword/element/text.rb', line 20

def text(text, style)
  @texts << { size: 'normal', text: text, style: style }
end

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



53
54
55
56
57
58
# File 'lib/rubyword/element/text.rb', line 53

def write(section=nil, xml=nil)
  @xml, @section = xml, section
  text = self.texts.pop
  return if text.to_s.empty?
  eval "write_#{text[:size]}(text)"
end

#write_normal(text) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/rubyword/element/text.rb', line 60

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