Class: Queries::TaxonDetermination::Filter
- Defined in:
- lib/queries/taxon_determination/filter.rb
Instance Attribute Summary collapse
-
#biological_collection_object_ids ⇒ Object
all Arrays.
-
#determiner_ids ⇒ Object
all Arrays.
-
#otu_ids ⇒ Object
all Arrays.
Attributes inherited from Query
#dynamic_limit, #options, #project_id, #query_string, #terms
Instance Method Summary collapse
-
#all ⇒ Object
TODO: Ugh, handle join more cleanly.
- #and_clauses ⇒ ActiveRecord::Relation
-
#base_query ⇒ Object
TODO: may require specific select('taxon_determinations.*, …') to function wth order etc.
-
#initialize(params = {}) ⇒ Filter
constructor
A new instance of Filter.
- #matching_biological_collection_object_ids ⇒ Object
- #matching_determiner_ids ⇒ Object
- #matching_otu_ids ⇒ Object
- #roles_table ⇒ Arel::Table
- #table ⇒ Arel::Table
- #where_sql ⇒ String
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, #levenshtein_distance, #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_ids ⇒ Object
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_ids ⇒ Object
all Arrays
6 7 8 |
# File 'lib/queries/taxon_determination/filter.rb', line 6 def determiner_ids @determiner_ids end |
#otu_ids ⇒ Object
all Arrays
6 7 8 |
# File 'lib/queries/taxon_determination/filter.rb', line 6 def otu_ids @otu_ids end |
Instance Method Details
#all ⇒ Object
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_clauses ⇒ 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_query ⇒ Object
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_ids ⇒ Object
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_ids ⇒ Object
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_ids ⇒ Object
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_table ⇒ Arel::Table
77 78 79 |
# File 'lib/queries/taxon_determination/filter.rb', line 77 def roles_table ::Role.arel_table end |
#table ⇒ Arel::Table
67 68 69 |
# File 'lib/queries/taxon_determination/filter.rb', line 67 def table ::TaxonDetermination.arel_table end |
#where_sql ⇒ 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 |