Class: Rubyword::Element::List

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

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

#listsObject

Returns the value of attribute lists.



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

def lists
  @lists
end

Instance Method Details

#save(text, level, style) ⇒ Object

write document and numbering



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

def save(text, level, style)
  @lists ||= Queue.new
  text = filter_text(text)
  @lists << {
    level: level.to_i - 1,
    text: text,
    style: style
  }
end

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubyword/element/list.rb', line 18

def write(section=nil, xml=nil)
  @xml = xml
  list = self.lists.pop
  @xml.send('w:p') {
    @xml.send('w:pPr') {
      @xml.send('w:numPr') {
        @xml.send('w:ilvl', 'w:val' => list[:level])
        @xml.send('w:numId', 'w:val' => 3)
      }
    }
    @xml.send('w:r') {
      Writer::Style::Word.new(@section, @xml, @rubyword).write(list[:style])
      @xml.send('w:t', {'xml:space' => 'preserve'}, list[:text])
    }
  }
end