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, #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.
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 40
def initialize(params)
@taxon_name_id = params[:taxon_name_id]
@subject_taxon_name_id = params[:subject_taxon_name_id]
@object_taxon_name_id = params[:object_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
11
12
13
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 11
def as_object
@as_object
end
|
#as_subject ⇒ Object
15
16
17
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 15
def as_subject
@as_subject
end
|
#object_taxon_name_id ⇒ Object
Match all relationships where object is this ID
29
30
31
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 29
def object_taxon_name_id
@object_taxon_name_id
end
|
#subject_taxon_name_id ⇒ Object
Match all relationships where subject is this ID
24
25
26
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 24
def subject_taxon_name_id
@subject_taxon_name_id
end
|
#taxon_name_id ⇒ Object
7
8
9
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 7
def taxon_name_id
@taxon_name_id
end
|
#taxon_name_relationship_set ⇒ Object
See corresponding constants in config/intialize/constants/taxon_name_relationships.rb
37
38
39
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 37
def taxon_name_relationship_set
@taxon_name_relationship_set
end
|
#taxon_name_relationship_type ⇒ Object
19
20
21
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 19
def taxon_name_relationship_type
@taxon_name_relationship_type
end
|
Instance Method Details
#all ⇒ ActiveRecord::Relation
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 136
def all
a = and_clauses
q = nil
if a
q = ::TaxonNameRelationship.where(a)
else
q = ::TaxonNameRelationship.all
end
q = q.where(project_id: project_id) if project_id
q
end
|
#and_clauses ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 115
def and_clauses
clauses = []
clauses += [
taxon_name_relationship_type_facet,
taxon_name_relationship_set_facet,
taxon_name_id_facet,
as_subject_facet,
as_object_facet,
].compact
return nil if clauses.empty?
a = clauses.shift
clauses.each do |b|
a = a.and(b)
end
a
end
|
#as_object_facet ⇒ ActiveRecord::Relation?
110
111
112
113
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 110
def as_object_facet
return nil if object_taxon_name_id.empty?
table[:object_taxon_name_id].eq_any(object_taxon_name_id)
end
|
#as_subject_facet ⇒ ActiveRecord::Relation?
104
105
106
107
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 104
def as_subject_facet
return nil if subject_taxon_name_id.empty?
table[:subject_taxon_name_id].eq_any(subject_taxon_name_id)
end
|
#relationship_types ⇒ Array
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 73
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
56
57
58
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 56
def table
::TaxonNameRelationship.arel_table
end
|
#taxon_name_id_facet ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 95
def taxon_name_id_facet
return nil if taxon_name_id.empty?
table[:subject_taxon_name_id].eq_any(taxon_name_id)
.or(
table[:object_taxon_name_id].eq_any(taxon_name_id)
)
end
|
#taxon_name_relationship_set_facet ⇒ Object
85
86
87
88
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 85
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
90
91
92
93
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 90
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
|