Class: Queries::Loan::Autocomplete

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/loan/autocomplete.rb

Instance Attribute Summary

Attributes inherited from Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Query

#alphabetic_strings, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_exact_id, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #simple_date, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (Autocomplete) initialize(string, project_id: nil)

Returns a new instance of Autocomplete

Parameters:

  • args (Hash)


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

def initialize(string, project_id: nil)
  super
end

Instance Method Details

- (Array) autocomplete

Returns:

  • (Array)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/queries/loan/autocomplete.rb', line 17

def autocomplete
  queries = [
    autocomplete_recipient_email,
    autocomplete_exact_date_sent,
    autocomplete_exact_date_requested,
    autocomplete_exact_date_received,
    autocomplete_exact_id,
    autocomplete_identifier_identifier_exact,
    autocomplete_identifier_cached_like,
  ]
  queries.compact!

  updated_queries = []
  queries.each_with_index do |q,i|
    a = q
    a = q.where(project_id: project_id) if project_id
    updated_queries[i] = a
  end

  result = []
  updated_queries.each do |q|
    result += q.to_a
    result.uniq!
    break if result.count > 19
  end

  result[0..40]
end

- (Object) autocomplete_exact_date_received



61
62
63
64
# File 'lib/queries/loan/autocomplete.rb', line 61

def autocomplete_exact_date_received
  o = table[:date_received].eq(query_string)
  ::Loan.where(o.to_sql)
end

- (Object) autocomplete_exact_date_requested



56
57
58
59
# File 'lib/queries/loan/autocomplete.rb', line 56

def autocomplete_exact_date_requested
  o = table[:date_requested].eq(query_string)
  ::Loan.where(o.to_sql)
end

- (Object) autocomplete_exact_date_sent



51
52
53
54
# File 'lib/queries/loan/autocomplete.rb', line 51

def autocomplete_exact_date_sent
  o = table[:date_sent].eq(query_string)
  ::Loan.where(o.to_sql)
end

- (Object) autocomplete_recipient_email



46
47
48
49
# File 'lib/queries/loan/autocomplete.rb', line 46

def autocomplete_recipient_email
  o = table[:recipient_email].matches('%' + query_string + '%')
  ::Loan.where(o.to_sql)
end

- (Scope) base_query

Returns:

  • (Scope)


67
68
69
# File 'lib/queries/loan/autocomplete.rb', line 67

def base_query
  ::Loan.select('loans.*')
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


72
73
74
# File 'lib/queries/loan/autocomplete.rb', line 72

def table
  ::Loan.arel_table
end

- (String) where_sql

Returns:

  • (String)


12
13
14
# File 'lib/queries/loan/autocomplete.rb', line 12

def where_sql
  with_project_id.and(or_and).to_sql
end