Class: Ambition::Adapters::AmbitiousSphinx::Base
- Inherits:
-
Object
- Object
- Ambition::Adapters::AmbitiousSphinx::Base
- Defined in:
- lib/ambition/adapters/ambitious_sphinx/base.rb
Overview
Helper for the other
Instance Method Summary collapse
-
#has_field?(str) ⇒ Boolean
Does the string have an Ultrasphinx field?.
-
#has_operator?(str) ⇒ Boolean
Does the string have any Ultrasphinx operators?.
-
#needs_quoting?(str) ⇒ Boolean
Should this string be quotified? It needs to happen if the string doesn’t have an operator or a field.
-
#quotify(str) ⇒ Object
Quote the string if it needs it.
Instance Method Details
#has_field?(str) ⇒ Boolean
Does the string have an Ultrasphinx field?
7 8 9 |
# File 'lib/ambition/adapters/ambitious_sphinx/base.rb', line 7 def has_field? str str =~ /:/ end |
#has_operator?(str) ⇒ Boolean
Does the string have any Ultrasphinx operators?
12 13 14 |
# File 'lib/ambition/adapters/ambitious_sphinx/base.rb', line 12 def has_operator? str str =~ /(AND|OR|NOT)/ end |
#needs_quoting?(str) ⇒ Boolean
Should this string be quotified? It needs to happen if the string doesn’t have an operator or a field.
18 19 20 |
# File 'lib/ambition/adapters/ambitious_sphinx/base.rb', line 18 def needs_quoting? str not (has_operator?(str) or has_field?(str)) end |
#quotify(str) ⇒ Object
Quote the string if it needs it.
23 24 25 26 27 28 29 |
# File 'lib/ambition/adapters/ambitious_sphinx/base.rb', line 23 def quotify str if needs_quoting?(str) %Q("#{str}") else str end end |