class AnyStyle::Feature::Category
Attributes
index[R]
Public Class Methods
new(index: [0, -1], strip: false)
click to toggle source
# File lib/anystyle/feature/category.rb 6 def initialize(index: [0, -1], strip: false) 7 @index, @strip = index, !!strip 8 end
Public Instance Methods
categorize(char)
click to toggle source
# File lib/anystyle/feature/category.rb 22 def categorize(char) 23 case char 24 when /\p{Lu}/ 25 :Lu 26 when /\p{Ll}/ 27 :Ll 28 when /\p{Lm}/ 29 :Lm 30 when /\p{L}/ 31 :L 32 when /\p{M}/ 33 :M 34 when /\p{N}/ 35 :N 36 when /\p{Pc}/ 37 :Pc 38 when /\p{Pd}/ 39 :Pd 40 when /\p{Ps}/ 41 :Ps 42 when /\p{Pe}/ 43 :Pe 44 when /\p{Pi}/ 45 :Pi 46 when /\p{Pf}/ 47 :Pf 48 when /\p{P}/ 49 :P 50 when /\p{S}/ 51 :S 52 when /\p{Zl}/ 53 :Zl 54 when /\p{Zp}/ 55 :Zp 56 when /\p{Z}/ 57 :Z 58 when /\p{C}/ 59 :C 60 else 61 :none 62 end 63 end
chars(token)
click to toggle source
# File lib/anystyle/feature/category.rb 14 def chars(token) 15 if strip? 16 token.strip.chars 17 else 18 token.chars 19 end 20 end
observe(token, **opts)
click to toggle source
# File lib/anystyle/feature/category.rb 10 def observe(token, **opts) 11 chars(token).values_at(*index).map { |char| categorize char } 12 end
strip?()
click to toggle source
# File lib/anystyle/feature/category.rb 65 def strip? 66 @strip 67 end