Class: AnyStyle::Feature::Ref

Inherits:
AnyStyle::Feature show all
Defined in:
lib/anystyle/feature/ref.rb

Instance Attribute Summary

Attributes inherited from AnyStyle::Feature

#precision

Instance Method Summary collapse

Methods inherited from AnyStyle::Feature

#initialize, #next, #prev, #ratio

Methods included from StringUtils

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

Constructor Details

This class inherits a constructor from AnyStyle::Feature

Instance Method Details

#observe(token, **opts) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/anystyle/feature/ref.rb', line 4

def observe(token, **opts)
  [
    symbolize(count(token, /\b(1[4-9]|20)\d\d\b/)),
    symbolize(count(token, /(\d[\(:;]\d)|(\d\s*\p{Pd}+\s*\d)|\bpp?\.|\bvols?\.|\b(nos?|nr|iss?|fasc)\.|n°|nº/i)),
    symbolize(count(token, /\b\p{Lu}\./)),
    symbolize(count(token, /\b(eds?\.|edited by|editors?|hg|hrsg|et al)\b/i)),
    token =~ /^\s*(\[\w+\]|\(\d+\)|\d+\.)\s+/ ? 'T' : 'F'
  ]
end

#symbolize(k) ⇒ Object



14
15
16
17
18
# File 'lib/anystyle/feature/ref.rb', line 14

def symbolize(k)
  return '-' if k < 1
  return '+' if k < 2
  return '*'
end