Class: AnyStyle::Feature::Number

Inherits:
AnyStyle::Feature show all
Defined in:
lib/anystyle/feature/number.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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/anystyle/feature/number.rb', line 4

def observe(token, **opts)
  case token
  when /\d[\(:;]\d/
    :volume
  when /^97[89](\p{Pd}?\d){10}$/,
       /^\d(\p{Pd}?\d){9}$/
    :isbn
  when /\b(1\d|20)\d\d\b/
    :year
  when /^\d\d\d\d$/
    :quad
  when /^\d\d\d$/
    :triple
  when /^\d\d$/
    :double
  when /^\d$/
    :single
  when /^\d+$/
    :all
  when /^\d+\p{Pd}+\d+$/
    :range
  when /^\p{Lu}[\p{Lu}\p{Pd}\/]+\d+[,.:]?$/
    :idnum
  when /\d\p{Alpha}{1,3}\b/i
    :ordinal
  when /\d/
    :numeric
  when /^([IVXLDCM]+|[ivx]+)\b/
    :roman
  else
    :none
  end
end