Class: RTF::ListTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/rtf/list.rb

Constant Summary collapse

Markers =
{
  :disc    => ListMarker.new('disc',    0x2022),
  :hyphen  => ListMarker.new('hyphen',  0x2043),
  :decimal => ListMarker.new('decimal'        )
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ ListTemplate

Returns a new instance of ListTemplate.



102
103
104
105
# File 'lib/rtf/list.rb', line 102

def initialize(id)
  @levels = []
  @id     = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



94
95
96
# File 'lib/rtf/list.rb', line 94

def id
  @id
end

Instance Method Details

#level_for(level, kind = :bullets) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/rtf/list.rb', line 107

def level_for(level, kind = :bullets)
  @levels[level-1] ||= begin
    # Only disc for now: we'll add support
    # for more customization options later
    marker = Markers[kind == :bullets ? :disc : :decimal]
    ListLevel.new(self, marker, level)
  end
end

#to_rtf(indent = 0) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/rtf/list.rb', line 116

def to_rtf(indent=0)
  prefix = indent > 0 ? ' ' * indent : ''

  text = "#{prefix}{\\list\\listtemplate#{id}\\listhybrid"
  @levels.each {|lvl| text << lvl.to_rtf}
  text << "{\\listname;}\\listid#{id}}\n"

  text
end