Class: Queries::TaxonNameRelationship::Filter
- Inherits:
-
Query
- Object
- Query
- Queries::TaxonNameRelationship::Filter
show all
- Defined in:
- lib/queries/taxon_name_relationship/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, #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.
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 29
def initialize(params)
@taxon_name_id = params[:taxon_name_id]
@as_object = (params[:as_object]&.downcase == 'true' ? true : false) if !params[:as_object].nil?
@as_subject = (params[:as_subject]&.downcase == 'true' ? true : false) if !params[:as_subject].nil?
@taxon_name_relationship_type = [params[:taxon_name_relationship_type]].flatten.compact
@taxon_name_relationship_set = [params[:taxon_name_relationship_set]].flatten.compact
@project_id = params[:project_id]
end
|
Instance Attribute Details
#as_object ⇒ Object
10
11
12
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 10
def as_object
@as_object
end
|
#as_subject ⇒ Object
14
15
16
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 14
def as_subject
@as_subject
end
|
#taxon_name_id ⇒ Object
6
7
8
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 6
def taxon_name_id
@taxon_name_id
end
|
#taxon_name_relationship_set ⇒ Object
See corresponding constants in config/intialize/constants/taxon_name_relationships.rb
26
27
28
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 26
def taxon_name_relationship_set
@taxon_name_relationship_set
end
|
#taxon_name_relationship_type ⇒ Object
18
19
20
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 18
def taxon_name_relationship_type
@taxon_name_relationship_type
end
|
Instance Method Details
#all ⇒ ActiveRecord::Relation
#and_clauses ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 87
def and_clauses
clauses = []
clauses += [
taxon_name_relationship_type_facet,
taxon_name_relationship_set_facet,
as_subject_facet,
as_object_facet,
as_either_facet
].compact
return nil if clauses.empty?
a = clauses.shift
clauses.each do |b|
a = a.and(b)
end
a
end
|
#as_either_facet ⇒ Object
81
82
83
84
85
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 81
def as_either_facet
return nil unless taxon_name_id && as_object.nil? && as_subject.nil?
table[:subject_taxon_name_id].eq(taxon_name_id)
.or(table[:object_taxon_name_id].eq(taxon_name_id))
end
|
#as_object_facet ⇒ ActiveRecord::Relation?
76
77
78
79
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 76
def as_object_facet
return nil unless taxon_name_id && as_object
table[:object_taxon_name_id].eq(taxon_name_id)
end
|
#as_subject_facet ⇒ ActiveRecord::Relation?
70
71
72
73
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 70
def as_subject_facet
return nil unless taxon_name_id && as_subject
table[:subject_taxon_name_id].eq(taxon_name_id)
end
|
#relationship_types ⇒ Array
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 47
def relationship_types
return [] unless taxon_name_relationship_set && taxon_name_relationship_set.any?
t = []
taxon_name_relationship_set.each do |i|
t += STATUS_TAXON_NAME_RELATIONSHIP_NAMES if i == 'status'
t += TAXON_NAME_RELATIONSHIP_NAMES_SYNONYM if i == 'synonym'
t += TAXON_NAME_RELATIONSHIP_NAMES_CLASSIFICATION if i == 'classification'
end
t
end
|
#table ⇒ Arel::Table
42
43
44
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 42
def table
::TaxonNameRelationship.arel_table
end
|
#taxon_name_relationship_set_facet ⇒ Object
59
60
61
62
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 59
def taxon_name_relationship_set_facet
return nil unless taxon_name_relationship_set && taxon_name_relationship_set.any?
table[:type].eq_any(relationship_types)
end
|
#taxon_name_relationship_type_facet ⇒ Object
64
65
66
67
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 64
def taxon_name_relationship_type_facet
return nil unless taxon_name_relationship_type && taxon_name_relationship_type.any?
table[:type].eq_any(taxon_name_relationship_type)
end
|