Class: Queries::TaxonNameRelationshipsFilterQuery
- Inherits:
-
Query
- Object
- Query
- Queries::TaxonNameRelationshipsFilterQuery
show all
- Defined in:
- lib/queries/taxon_name_relationships_filter_query.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(taxon_name_id: nil, project_id: nil, **keyword_args) ⇒ TaxonNameRelationshipsFilterQuery
Returns a new instance of TaxonNameRelationshipsFilterQuery.
10
11
12
13
14
15
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 10
def initialize(taxon_name_id: nil, project_id: nil, **keyword_args)
return if taxon_name_id.nil?
@taxon_name_id = taxon_name_id
@project_id = project_id
@keyword_args = keyword_args
end
|
Instance Attribute Details
#keyword_args ⇒ Object
Returns the value of attribute keyword_args.
7
8
9
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 7
def keyword_args
@keyword_args
end
|
#taxon_name_id ⇒ Object
Returns the value of attribute taxon_name_id.
5
6
7
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 5
def taxon_name_id
@taxon_name_id
end
|
Instance Method Details
#and_clauses ⇒ ActiveRecord::Relation?
66
67
68
69
70
71
72
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 66
def and_clauses
if relationship_types.any?
table[:type].eq_any(relationship_types)
else
nil
end
end
|
#as_object ⇒ ActiveRecord::Relation?
96
97
98
99
100
101
102
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 96
def as_object
if as_object?
table[:object_taxon_name_id].eq(taxon_name_id)
else
nil
end
end
|
#as_object? ⇒ Boolean
28
29
30
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 28
def as_object?
keyword_args[:as_object] == 'true'
end
|
#as_subject ⇒ ActiveRecord::Relation?
87
88
89
90
91
92
93
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 87
def as_subject
if as_subject?
table[:subject_taxon_name_id].eq(taxon_name_id)
else
nil
end
end
|
#as_subject? ⇒ Boolean
23
24
25
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 23
def as_subject?
keyword_args[:as_subject] == 'true'
end
|
#of_type ⇒ Array
18
19
20
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 18
def of_type
keyword_args[:of_type]
end
|
#of_types ⇒ Array
49
50
51
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 49
def of_types
keyword_args[:of_types] || []
end
|
#or_clauses ⇒ ActiveRecord::Relation
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 33
def or_clauses
clauses = [
as_subject,
as_object,
].compact
clauses.push as_subject.or(as_object) if clauses.empty?
a = clauses.shift
clauses.each do |b|
a = a.or(b)
end
a
end
|
#relationship_types ⇒ Array
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 54
def relationship_types
t = []
of_types.each do |i|
t = t + STATUS_TAXON_NAME_RELATIONSHIP_NAMES if i == 'status'
t = t + TAXON_NAME_RELATIONSHIP_NAMES_SYNONYM if i == 'synonym'
t = t + TAXON_NAME_RELATIONSHIP_NAMES_CLASSIFICATION if i == 'classification'
end
t
end
|
#table ⇒ Arel::Table
82
83
84
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 82
def table
::TaxonNameRelationship.arel_table
end
|
#where_sql ⇒ String
75
76
77
78
79
|
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 75
def where_sql
clause = or_clauses
clause = clause.and(and_clauses) if and_clauses
clause.to_sql
end
|