Class: Ambition::Adapters::AmbitiousSphinx::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ambition/adapters/ambitious_sphinx/base.rb

Overview

Helper for the other

Direct Known Subclasses

Query, Select, Slice, Sort

Instance Method Summary collapse

Instance Method Details

#has_field?(str) ⇒ Boolean

Does the string have an Ultrasphinx field?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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