Class: Queries::ObservationMatrix::Filter

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/observation_matrix/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, #alphanumeric_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, #string_fragments, #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.



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

def initialize(params = {})
  @observation_matrix_id
end

Instance Attribute Details

#observation_matrix_idObject

Returns the value of attribute observation_matrix_id.



5
6
7
# File 'lib/queries/observation_matrix/filter.rb', line 5

def observation_matrix_id
  @observation_matrix_id
end

Instance Method Details

#allObject



42
43
44
45
46
47
48
# File 'lib/queries/observation_matrix/filter.rb', line 42

def all
  if w = where_sql
    base_query.where(w).distinct
  else
    base_query.all
  end
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


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

def and_clauses
  clauses = [
    matching_observation_matrix_id,
  ].compact

  return nil if clauses.empty?

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

  a
end

#base_queryObject



55
56
57
# File 'lib/queries/observation_matrix/filter.rb', line 55

def base_query
  ::ObservationMatrix.select('observation_matrices.*')
end

#matching_observation_matrix_idObject



31
32
33
# File 'lib/queries/observation_matrix/filter.rb', line 31

def matching_observation_matrix_id
  observation_matrix_id.empty? ? nil : table[:id].eq_any(observation_matrix_id)
end

#tableArel::Table

Returns:

  • (Arel::Table)


51
52
53
# File 'lib/queries/observation_matrix/filter.rb', line 51

def table
  ::ObservationMatrix.arel_table
end

#where_sqlString?

Returns:

  • (String, nil)


36
37
38
39
40
# File 'lib/queries/observation_matrix/filter.rb', line 36

def where_sql
  a = and_clauses
  return nil if a.nil?
  a.to_sql
end