Module: Rosette::Core::PhraseIndexPolicy
- Included in:
- Phrase
- Defined in:
- lib/rosette/core/extractor/phrase/phrase_index_policy.rb
Overview
Defines the logic for which field should be used to index a phrase. Phrases can be indexed either by key or meta key. The logic in this module is designed to determine which of these fields to use for a particular phrase, taking into consideration nil and blank values. By default, phrases are indexed by meta key. If however a phrase has a nil or blank meta key, the key should be used as the index value instead.
Must be mixed into an object that responds to Phrase methods, specifically key and meta_key.
Class Method Summary collapse
-
.index_key(key, meta_key) ⇒ Symbol
Determines which key should be used for indexing.
-
.index_value(key, meta_key) ⇒ String
Determines which value should be used for indexing.
Instance Method Summary collapse
-
#index_key ⇒ Symbol
Determines which key should be used for indexing.
-
#index_value ⇒ String
Determines which value should be used for indexing.
Class Method Details
.index_key(key, meta_key) ⇒ Symbol
Determines which key should be used for indexing.
47 48 49 50 51 52 53 |
# File 'lib/rosette/core/extractor/phrase/phrase_index_policy.rb', line 47 def self.index_key(key, ) if ! || .empty? :key else :meta_key end end |
.index_value(key, meta_key) ⇒ String
Determines which value should be used for indexing.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rosette/core/extractor/phrase/phrase_index_policy.rb', line 62 def self.index_value(key, ) value = case index_key(key, ) when :key then key else end case value when NilClass '' else value end end |
Instance Method Details
#index_key ⇒ Symbol
Determines which key should be used for indexing.
79 80 81 |
# File 'lib/rosette/core/extractor/phrase/phrase_index_policy.rb', line 79 def index_key PhraseIndexPolicy.index_key(key, ) end |
#index_value ⇒ String
Determines which value should be used for indexing.
88 89 90 |
# File 'lib/rosette/core/extractor/phrase/phrase_index_policy.rb', line 88 def index_value PhraseIndexPolicy.index_value(key, ) end |