Class: AnyStyle::Page

Inherits:
Object
  • Object
show all
Extended by:
StringUtils
Defined in:
lib/anystyle/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StringUtils

canonize, count, display_chars, display_width, indent, nnum, page_break?, scrub, strip_html, transliterate

Constructor Details

#initialize(lines = [], width: 0) ⇒ Page

Returns a new instance of Page


37
38
39
40
# File 'lib/anystyle/page.rb', line 37

def initialize(lines = [], width: 0)
  @lines = lines
  @width = width
end

Instance Attribute Details

#linesObject

Returns the value of attribute lines


35
36
37
# File 'lib/anystyle/page.rb', line 35

def lines
  @lines
end

#widthObject

Returns the value of attribute width


35
36
37
# File 'lib/anystyle/page.rb', line 35

def width
  @width
end

Class Method Details

.parse(lines, document) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/anystyle/page.rb', line 6

def parse(lines, document)
  pages, current, width = [], [], 0

  lines.each do |line|
    chars = display_chars(line.value)
    document.line_counts[chars] += 1
    document.nnum_counts[nnum(chars)] += 1

    if page_break?(line.value)
      unless current.empty?
        pages << new(current, width: width)
      end

      current = [line]
      width = chars.length
    else
      current << line
      width = [width, chars.length].max
    end
  end

  unless current.empty?
    pages << new(current, width: width)
  end

  pages
end

Instance Method Details

#inspectObject


46
47
48
# File 'lib/anystyle/page.rb', line 46

def inspect
  "#<AnyStyle::Page size={#{size}} width={#{width}}>"
end

#sizeObject


42
43
44
# File 'lib/anystyle/page.rb', line 42

def size
  lines.size
end