Class: AnyStyle::Feature::Line
- Inherits:
-
AnyStyle::Feature
- Object
- AnyStyle::Feature
- AnyStyle::Feature::Line
- Defined in:
- lib/anystyle/feature/line.rb
Instance Attribute Summary
Attributes inherited from AnyStyle::Feature
Instance Method Summary collapse
Methods inherited from AnyStyle::Feature
#initialize, #next, #prev, #ratio
Methods included from StringUtils
canonize, count, display_chars, display_width, indent, page_break?, scrub, transliterate
Constructor Details
This class inherits a constructor from AnyStyle::Feature
Instance Method Details
#classify(chars) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/anystyle/feature/line.rb', line 25 def classify(chars) case chars when /\.\s*\.\s*\.\s*\.|……+/ :toc when /\s\s\s\d+$/ :num when /^\s*(Table|Fig(ure|\.))/ :cap else :none end end |
#observe(token, page:, **opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/anystyle/feature/line.rb', line 4 def observe(token, page:, **opts) chars = display_chars(token).rstrip lttrs = count(chars, /\p{L}/) upper = count(chars, /\p{Lu}/) punct = count(chars, /[\p{Pd}:.,&\(\)"'”„’‚´«「『‘“`»」』]/) white = count(chars, /\s/) width = chars.length [ lttrs, width, ratio(upper, lttrs), ratio(lttrs, chars.length), ratio(white, chars.length), ratio(punct, chars.length), ratio(width, page.width), classify(chars) ] end |