Class: AnyStyle::Feature::Affix
Instance Attribute Summary collapse
#precision
Instance Method Summary
collapse
#next, #prev, #ratio
canonize, count, display_chars, display_width, indent, nnum, page_break?, scrub, strip_html, transliterate
Constructor Details
#initialize(size: 4, prefix: true, suffix: false) ⇒ Affix
Returns a new instance of Affix.
6
7
8
|
# File 'lib/anystyle/feature/affix.rb', line 6
def initialize(size: 4, prefix: true, suffix: false)
@size, @suffix = size, (suffix || !prefix)
end
|
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
4
5
6
|
# File 'lib/anystyle/feature/affix.rb', line 4
def size
@size
end
|
Instance Method Details
#build(chars) ⇒ Object
30
31
32
|
# File 'lib/anystyle/feature/affix.rb', line 30
def build(chars)
(1..size).map { |n| yield chars.take(n) }
end
|
14
15
16
17
18
19
20
|
# File 'lib/anystyle/feature/affix.rb', line 14
def (token)
if suffix?
token.chars.reverse.take(size)
else
token.chars.take(size)
end
end
|
#join(chars) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/anystyle/feature/affix.rb', line 22
def join(chars)
if suffix?
chars.reverse.join('')
else
chars.join('')
end
end
|
#observe(token, **opts) ⇒ Object
10
11
12
|
# File 'lib/anystyle/feature/affix.rb', line 10
def observe(token, **opts)
build((token)) { |chars| join(chars) }
end
|
#prefix? ⇒ Boolean
38
39
40
|
# File 'lib/anystyle/feature/affix.rb', line 38
def prefix?
!suffix?
end
|
#suffix? ⇒ Boolean
34
35
36
|
# File 'lib/anystyle/feature/affix.rb', line 34
def suffix?
!!@suffix
end
|