Class: Queries::TaxonDetermination::Filter

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/taxon_determination/filter.rb

Instance Attribute Summary (collapse)

Attributes inherited from Query

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

Instance Method Summary (collapse)

Methods inherited from Query

#alphabetic_strings, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_identifier_cached_exact, #autocomplete_identifier_cached_like, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #identifier_table, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_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_id, #with_identifier, #with_identifier_like, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (Filter) initialize(params = {})

Returns a new instance of Filter



8
9
10
11
12
13
14
15
# File 'lib/queries/taxon_determination/filter.rb', line 8

def initialize(params = {})
  @otu_ids = params[:otu_ids]
  @biological_collection_object_ids = params[:biological_collection_object_ids]
  @determiner_ids = params[:determiner_ids]
  @otu_ids ||= []
  @biological_collection_object_ids ||= []
  @determiner_ids ||= []
end

Instance Attribute Details

- (Object) biological_collection_object_ids

all Arrays



6
7
8
# File 'lib/queries/taxon_determination/filter.rb', line 6

def biological_collection_object_ids
  @biological_collection_object_ids
end

- (Object) determiner_ids

all Arrays



6
7
8
# File 'lib/queries/taxon_determination/filter.rb', line 6

def determiner_ids
  @determiner_ids
end

- (Object) otu_ids

all Arrays



6
7
8
# File 'lib/queries/taxon_determination/filter.rb', line 6

def otu_ids
  @otu_ids
end

Instance Method Details

- (Object) all

TODO: Ugh, handle join more cleanly



51
52
53
54
55
56
57
# File 'lib/queries/taxon_determination/filter.rb', line 51

def all
  if determiner_ids.empty?
    base_query.where(where_sql).distinct
  else
    base_query.joins(:roles).where(where_sql).where( roles_table[:person_id].eq_any(determiner_ids).to_sql )
  end
end

- (ActiveRecord::Relation) and_clauses

Returns:

  • (ActiveRecord::Relation)


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/queries/taxon_determination/filter.rb', line 18

def and_clauses
  clauses = [
    matching_otu_ids,
    matching_biological_collection_object_ids,
  ].compact

  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
 
  a
end

- (Object) base_query



64
65
66
# File 'lib/queries/taxon_determination/filter.rb', line 64

def base_query
  ::TaxonDetermination.includes(:determiners)
end

- (Object) matching_biological_collection_object_ids



36
37
38
# File 'lib/queries/taxon_determination/filter.rb', line 36

def matching_biological_collection_object_ids
  biological_collection_object_ids.empty? ? nil : table[:biological_collection_object_id].eq_any(biological_collection_object_ids)
end

- (Object) matching_determiner_ids



40
41
42
# File 'lib/queries/taxon_determination/filter.rb', line 40

def matching_determiner_ids
  determiner_ids.empty? ? nil : roles_table[:person_id].eq_any(determiner_ids)
end

- (Object) matching_otu_ids



32
33
34
# File 'lib/queries/taxon_determination/filter.rb', line 32

def matching_otu_ids
  otu_ids.empty? ? nil : table[:otu_id].eq_any(otu_ids)
end

- (Arel::Table) roles_table

Returns:

  • (Arel::Table)


69
70
71
# File 'lib/queries/taxon_determination/filter.rb', line 69

def roles_table
  ::Role.arel_table
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


60
61
62
# File 'lib/queries/taxon_determination/filter.rb', line 60

def table
  ::TaxonDetermination.arel_table
end

- (String) where_sql

Returns:

  • (String)


45
46
47
48
# File 'lib/queries/taxon_determination/filter.rb', line 45

def where_sql
  return ::TaxonDetermination.none if and_clauses.nil?
  and_clauses.to_sql
end