Class: RTF::ListLevel
- Inherits:
-
Object
- Object
- RTF::ListLevel
- Defined in:
- lib/rtf/list.rb
Constant Summary collapse
- ValidLevels =
(1..9)
- LevelTabs =
[ 220, 720, 1133, 1700, 2267, 2834, 3401, 3968, 4535, 5102, 5669, 6236, 6803 ].freeze
- ResetTabs =
[560].concat(LevelTabs[2..-1]).freeze
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#marker ⇒ Object
readonly
Returns the value of attribute marker.
Instance Method Summary collapse
- #id ⇒ Object
- #indent ⇒ Object
-
#initialize(template, marker, level) ⇒ ListLevel
constructor
A new instance of ListLevel.
- #reset_tabs ⇒ Object
- #tabs ⇒ Object
- #to_rtf(indent = 0) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(template, marker, level) ⇒ ListLevel
Returns a new instance of ListLevel.
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rtf/list.rb', line 140 def initialize(template, marker, level) unless marker.kind_of? ListMarker RTFError.fire("Invalid marker #{marker.inspect}") end unless ValidLevels.include? level RTFError.fire("Invalid list level: #{level}") end @template = template @level = level @marker = marker end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
138 139 140 |
# File 'lib/rtf/list.rb', line 138 def level @level end |
#marker ⇒ Object (readonly)
Returns the value of attribute marker.
138 139 140 |
# File 'lib/rtf/list.rb', line 138 def marker @marker end |
Instance Method Details
#id ⇒ Object
181 182 183 |
# File 'lib/rtf/list.rb', line 181 def id @id ||= @template.id * 10 + level end |
#indent ⇒ Object
185 186 187 |
# File 'lib/rtf/list.rb', line 185 def indent @indent ||= level * 720 end |
#reset_tabs ⇒ Object
158 159 160 |
# File 'lib/rtf/list.rb', line 158 def reset_tabs ResetTabs end |
#tabs ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rtf/list.rb', line 162 def tabs @tabs ||= begin tabs = LevelTabs.dup # Kernel#tap would be prettier here (@level - 1).times do # Reverse-engineered while looking at Textedit.app # generated output: they already made sure that it # would look good on every RTF editor :-p # a, = tabs.shift(3) a,b = a + 720, a + 1220 tabs.shift while tabs.first < b tabs.unshift a, b end tabs end end |
#to_rtf(indent = 0) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/rtf/list.rb', line 189 def to_rtf(indent=0) prefix = indent > 0 ? ' ' * indent : '' text = "#{prefix}{\\listlevel\\levelstartat1" # Marker type. The first declaration is for Backward Compatibility (BC). nfc = @marker.number_type text << "\\levelnfc#{nfc}\\levelnfcn#{nfc}" # Justification, currently only left justified (0). First decl for BC. text << '\leveljc0\leveljcn0' # Character that follows the level text, currently only TAB. text << '\levelfollow0' # BC: Minimum distance from the left & right edges. text << '\levelindent0\levelspace360' # Marker name text << "{\\*\\levelmarker #{@marker.name}}" # Marker text format text << "{\\leveltext\\leveltemplateid#{id}#{@marker.template_format};}" text << '{\levelnumbers;}' # The actual spacing text << "\\fi-360\\li#{self.indent}\\lin#{self.indent}}\n" end |
#type ⇒ Object
154 155 156 |
# File 'lib/rtf/list.rb', line 154 def type @marker.type end |