Class: Queries::RepositoryAutocompleteQuery

Inherits:
Object
  • Object
show all
Includes:
Arel::Nodes
Defined in:
lib/queries/repository_autocomplete_query.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RepositoryAutocompleteQuery) initialize(string)

Returns a new instance of RepositoryAutocompleteQuery



9
10
11
# File 'lib/queries/repository_autocomplete_query.rb', line 9

def initialize(string)
  build_terms(string)
end

Instance Attribute Details

- (Object) terms

Returns the value of attribute terms



7
8
9
# File 'lib/queries/repository_autocomplete_query.rb', line 7

def terms
  @terms
end

Instance Method Details

- (Object) acronym



41
42
43
# File 'lib/queries/repository_autocomplete_query.rb', line 41

def acronym
  table[:acronym].matches_any(@terms)
end

- (Object) all



25
26
27
# File 'lib/queries/repository_autocomplete_query.rb', line 25

def all 
  Repository.where(where_sql)
end

- (Object) build_terms(string)



17
18
19
# File 'lib/queries/repository_autocomplete_query.rb', line 17

def build_terms(string)
  @terms = string.split(/\s/).collect{|t| [t, "#{t}%", "#{t}%"] }.flatten 
end

- (Object) named



37
38
39
# File 'lib/queries/repository_autocomplete_query.rb', line 37

def named
  table[:name].matches_any(@terms)
end

- (Object) table



33
34
35
# File 'lib/queries/repository_autocomplete_query.rb', line 33

def table
  Repository.arel_table
end

- (Object) taxon_name_table



29
30
31
# File 'lib/queries/repository_autocomplete_query.rb', line 29

def taxon_name_table
  Repository.arel_table
end

- (Object) where_sql



21
22
23
# File 'lib/queries/repository_autocomplete_query.rb', line 21

def where_sql
  named.or(acronym).to_sql
end