Class: RediSearcher::Schema::Field
- Inherits:
-
Object
- Object
- RediSearcher::Schema::Field
- Defined in:
- lib/redi_searcher/schema/field.rb
Constant Summary collapse
- OPTIONS_FLAGS =
{ text: [:no_stem], all: [:sortable, :no_index] }
- OPTIONS_PARAMS =
{ text: [:phonetic, :weight], tag: [:separator] }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #flags_for_type(type, **options) ⇒ Object
-
#initialize(name, type, **options) ⇒ Field
constructor
A new instance of Field.
- #params_for_type(type, **options) ⇒ Object
- #serialize ⇒ Object
Constructor Details
#initialize(name, type, **options) ⇒ Field
Returns a new instance of Field.
16 17 18 19 20 21 |
# File 'lib/redi_searcher/schema/field.rb', line 16 def initialize(name, type, **) = type == :tag ? {separator: ','} : {} @name = name @type = type @options = .deep_merge() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/redi_searcher/schema/field.rb', line 14 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/redi_searcher/schema/field.rb', line 14 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/redi_searcher/schema/field.rb', line 14 def type @type end |
Instance Method Details
#flags_for_type(type, **options) ⇒ Object
27 28 29 30 31 |
# File 'lib/redi_searcher/schema/field.rb', line 27 def flags_for_type(type, **) self.class::OPTIONS_FLAGS[type].to_a.map do |key| key.to_s.upcase if [key] end.compact end |
#params_for_type(type, **options) ⇒ Object
33 34 35 36 37 |
# File 'lib/redi_searcher/schema/field.rb', line 33 def params_for_type(type, **) self.class::OPTIONS_PARAMS[type].to_a.map do |key| [key.to_s.upcase, *[key]] unless [key].nil? end.compact end |
#serialize ⇒ Object
23 24 25 |
# File 'lib/redi_searcher/schema/field.rb', line 23 def serialize [name.to_s, type.to_s.upcase, flags_for_type(type, ), params_for_type(type, ), flags_for_type(:all, )].flatten end |