Class: RediSearch::Schema::NumericField
- Inherits:
-
Field
- Object
- Field
- RediSearch::Schema::NumericField
show all
- Defined in:
- lib/redi_search/schema/numeric_field.rb
Instance Method Summary
collapse
Methods inherited from Field
#coerce, #name, #serialize
Constructor Details
#initialize(name, sortable: false, no_index: false, &block) ⇒ NumericField
Returns a new instance of NumericField.
6
7
8
9
10
11
|
# File 'lib/redi_search/schema/numeric_field.rb', line 6
def initialize(name, sortable: false, no_index: false, &block)
@name = name
@sortable = sortable
@no_index = no_index
@value_block = block
end
|
Instance Method Details
#cast(value) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/redi_search/schema/numeric_field.rb', line 20
def cast(value)
if value.to_s.include?(".")
value.to_f
else
value.to_i
end
end
|
#to_a ⇒ Object
13
14
15
16
17
18
|
# File 'lib/redi_search/schema/numeric_field.rb', line 13
def to_a
query = [name.to_s, "NUMERIC"]
query += boolean_options_string
query
end
|