Class: Queries::ObservationMatrixRow::Filter

Inherits:
Query::Filter show all
Defined in:
lib/queries/observation_matrix_row/filter.rb

Constant Summary collapse

PARAMS =
[
  :observation_object_type,
  :observation_object_id,
  :observation_matrix_id,
  :observation_matrix_row_id,
  observation_matrix_row_id: []
].freeze

Constants inherited from Query::Filter

Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES

Instance Attribute Summary collapse

Attributes inherited from Query::Filter

#api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #data_attribute_query, #descriptor_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #taxon_name_query, #venn, #venn_mode

Attributes inherited from Query

#query_string, #terms

Instance Method Summary collapse

Methods inherited from Query::Filter

#all_and_clauses, #all_merge_clauses, #annotator_and_clauses, #annotator_merge_clauses, annotator_params, api_except_params, api_excluded_params, #apply_venn, #attribute_exact_facet, base_filter, #deep_permit, included_annotator_facets, inverted_subqueries, #model_id_facet, #object_global_id_facet, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #query_name, #set_nested_queries, #shared_and_clauses, #subquery_vector, #venn_query

Methods inherited from Query

#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces

Constructor Details

#initialize(query_params) ⇒ Filter

Returns a new instance of Filter.



21
22
23
24
25
26
27
28
29
# File 'lib/queries/observation_matrix_row/filter.rb', line 21

def initialize(query_params)
  super
  @observation_object_type = params[:observation_object_type]
  @observation_object_id = params[:observation_object_id]
  @project_id = params[:project_id]
  @observation_object_id_vector = params[:observation_object_id_vector]
  @observation_matrix_id = params[:observation_matrix_id]
  @observation_matrix_row_id = params[:observation_matrix_row_id]
end

Instance Attribute Details

#observation_matrix_idObject

Returns the value of attribute observation_matrix_id.



15
16
17
# File 'lib/queries/observation_matrix_row/filter.rb', line 15

def observation_matrix_id
  @observation_matrix_id
end

#observation_object_idObject

Returns the value of attribute observation_object_id.



14
15
16
# File 'lib/queries/observation_matrix_row/filter.rb', line 14

def observation_object_id
  @observation_object_id
end

#observation_object_id_vectorObject (readonly)

Returns the value of attribute observation_object_id_vector.



19
20
21
# File 'lib/queries/observation_matrix_row/filter.rb', line 19

def observation_object_id_vector
  @observation_object_id_vector
end

#observation_object_typeObject

Returns the value of attribute observation_object_type.



13
14
15
# File 'lib/queries/observation_matrix_row/filter.rb', line 13

def observation_object_type
  @observation_object_type
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/queries/observation_matrix_row/filter.rb', line 87

def all
  a = and_clauses
  b = merge_clauses

  q = nil
  if a && b
    q = b.where(a)
  elsif a
    q = ::ObservationMatrixRow.where(a)
  elsif b
    q = b
  else
    q = ::ObservationMatrixRow.all
  end

  q = q.where(project_id:) if project_id
  q
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/queries/observation_matrix_row/filter.rb', line 45

def and_clauses
  clauses = [
    matching_observation_matrix_id,
    matching_observation_object_id,
    matching_observation_object_type,
  ].compact

  return nil if clauses.empty?

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

#matching_observation_matrix_idObject



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

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

#matching_observation_object_idObject



71
72
73
# File 'lib/queries/observation_matrix_row/filter.rb', line 71

def matching_observation_object_id
  observation_object_id.empty? ? nil : table[:observation_object_id].in(observation_object_id)
end

#matching_observation_object_typeObject



75
76
77
# File 'lib/queries/observation_matrix_row/filter.rb', line 75

def matching_observation_object_type
  observation_object_type.blank? ? nil : table[:observation_object_type].eq(observation_object_type)
end

#merge_clausesObject



61
62
63
64
65
# File 'lib/queries/observation_matrix_row/filter.rb', line 61

def merge_clauses
  clauses = []

  return nil if clauses.empty?
end

#observation_matrix_row_idObject



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

def observation_matrix_row_id
  [@observation_matrix_row_id].flatten.compact
end

#where_sqlString?

Returns:

  • (String, nil)


80
81
82
83
84
# File 'lib/queries/observation_matrix_row/filter.rb', line 80

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