Class: AnyStyle::Document::Page
- Inherits:
-
Object
- Object
- AnyStyle::Document::Page
- Extended by:
- StringUtils
- Defined in:
- lib/anystyle/document.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(lines = [], width: 0) ⇒ Page
constructor
A new instance of Page.
- #inspect ⇒ Object
- #size ⇒ Object
Methods included from StringUtils
canonize, count, display_chars, display_width, indent, page_break?, scrub, transliterate
Constructor Details
#initialize(lines = [], width: 0) ⇒ Page
Returns a new instance of Page.
250 251 252 253 |
# File 'lib/anystyle/document.rb', line 250 def initialize(lines = [], width: 0) @lines = lines @width = width end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
248 249 250 |
# File 'lib/anystyle/document.rb', line 248 def lines @lines end |
#width ⇒ Object
Returns the value of attribute width.
248 249 250 |
# File 'lib/anystyle/document.rb', line 248 def width @width end |
Class Method Details
.parse(lines) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/anystyle/document.rb', line 223 def parse(lines) pages, current, width = [], [], 0 lines.each do |line| if page_break?(line.value) unless current.empty? pages << new(current, width: width) end current = [line] width = display_width(line.value) else current << line width = [width, display_width(line.value)].max end end unless current.empty? pages << new(current, width: width) end pages end |
Instance Method Details
#inspect ⇒ Object
259 260 261 |
# File 'lib/anystyle/document.rb', line 259 def inspect "#<AnyStyle::Document::Page size={#{size}} width={#{width}}>" end |
#size ⇒ Object
255 256 257 |
# File 'lib/anystyle/document.rb', line 255 def size lines.size end |