Module: Iriq::Inflector
- Defined in:
- lib/iriq/inflector.rb
Overview
Singularization with a swappable adapter.
By default uses ActiveSupport's inflector if it can be required, otherwise
falls back to BuiltinAdapter. Override globally:
Iriq::Inflector.adapter = MyAdapter
And reset to default with Iriq::Inflector.reset_adapter!.
Defined Under Namespace
Modules: ActiveSupportAdapter, BuiltinAdapter
Constant Summary
collapse
- CACHE_MAX =
Vocabulary is bounded in practice; cache + cap matches the
SegmentClassifier strategy.
10_000
Class Method Summary
collapse
Class Method Details
.adapter ⇒ Object
27
28
29
|
# File 'lib/iriq/inflector.rb', line 27
def adapter
@adapter ||= default_adapter
end
|
.adapter=(value) ⇒ Object
31
32
33
34
|
# File 'lib/iriq/inflector.rb', line 31
def adapter=(value)
@adapter = value
@cache = {} end
|
.default_adapter ⇒ Object
.reset_adapter! ⇒ Object
36
37
38
39
|
# File 'lib/iriq/inflector.rb', line 36
def reset_adapter!
@adapter = nil
@cache = {}
end
|
.singularize(word) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/iriq/inflector.rb', line 18
def singularize(word)
cache = (@cache ||= {})
cached = cache[word]
return cached if cached
cache.clear if cache.size >= CACHE_MAX
cache[word] = adapter.singularize(word)
end
|