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, #attribute_exact_facet, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years

Constructor Details

#initialize(params = {}) ⇒ Filter

Returns a new instance of Filter



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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]
     
  if !params[:collection_object_id].blank? 
    @biological_collection_object_ids ||= []
    @biological_collection_object_ids.push(params[:collection_object_id])
  end

  @determiner_ids = params[:determiner_ids]
  
  @otu_ids.push(params[:otu_id]) unless params[:otu_id].blank?
  @biological_collection_object_ids ||= []
  @determiner_ids ||= []
end

Instance Attribute Details

#biological_collection_object_idsObject

all Arrays



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

def biological_collection_object_ids
  @biological_collection_object_ids
end

#determiner_idsObject

all Arrays



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

def determiner_ids
  @determiner_ids
end

#otu_idsObject

all Arrays



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

def otu_ids
  @otu_ids
end

Instance Method Details

#allObject

TODO: Ugh, handle join more cleanly



58
59
60
61
62
63
64
# File 'lib/queries/taxon_determination/filter.rb', line 58

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

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/queries/taxon_determination/filter.rb', line 25

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

#base_queryObject

TODO: may require specific select('taxon_determinations.*, …') to function wth order etc.



72
73
74
# File 'lib/queries/taxon_determination/filter.rb', line 72

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

#matching_biological_collection_object_idsObject



43
44
45
# File 'lib/queries/taxon_determination/filter.rb', line 43

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

#matching_determiner_idsObject



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

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

#matching_otu_idsObject



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

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

#roles_tableArel::Table

Returns:

  • (Arel::Table)


77
78
79
# File 'lib/queries/taxon_determination/filter.rb', line 77

def roles_table
  ::Role.arel_table
end

#tableArel::Table

Returns:

  • (Arel::Table)


67
68
69
# File 'lib/queries/taxon_determination/filter.rb', line 67

def table
  ::TaxonDetermination.arel_table
end

#where_sqlString

Returns:

  • (String)


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

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