Class: Queries::TaxonNameRelationshipsFilterQuery

Inherits:
Query
  • Object
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, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_identifier_cached_exact, #autocomplete_identifier_cached_like, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #identifier_table, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_cached, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #simple_date, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (TaxonNameRelationshipsFilterQuery) initialize(taxon_name_id: nil, project_id: nil, **keyword_args)

Returns a new instance of TaxonNameRelationshipsFilterQuery

Parameters:

  • args (Hash)


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

- (Object) keyword_args

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

- (Object) taxon_name_id

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

- (ActiveRecord::Relation?) and_clauses

Returns:

  • (ActiveRecord::Relation, nil)


65
66
67
68
69
70
71
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 65

def and_clauses
  if relationship_types.any?
    table[:type].eq_any(relationship_types)
  else
    nil
  end
end

- (ActiveRecord::Relation?) as_object

Returns:

  • (ActiveRecord::Relation, nil)


95
96
97
98
99
100
101
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 95

def as_object
  if as_object?
    table[:object_taxon_name_id].eq(taxon_name_id)
  else
    nil
  end
end

- (Boolean) as_object?

Returns:

  • (Boolean)


28
29
30
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 28

def as_object?
  keyword_args[:as_object] == 'true'
end

- (ActiveRecord::Relation?) as_subject

Returns:

  • (ActiveRecord::Relation, nil)


86
87
88
89
90
91
92
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 86

def as_subject
  if as_subject?
    table[:subject_taxon_name_id].eq(taxon_name_id)
  else
    nil
  end
end

- (Boolean) as_subject?

Returns:

  • (Boolean)


23
24
25
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 23

def as_subject?
  keyword_args[:as_subject] == 'true'
end

- (Array) of_type

Returns:

  • (Array)


18
19
20
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 18

def of_type
  keyword_args[:of_type]
end

- (Array) of_types

Returns:

  • (Array)


49
50
51
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 49

def of_types
  keyword_args[:of_type] || []
end

- (ActiveRecord::Relation) or_clauses

Returns:

  • (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

- (Array) relationship_types

Returns:

  • (Array)


54
55
56
57
58
59
60
61
62
# 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_RELATIONSHIPS_JSON[:typification][:all].keys if i == 'type'
  end
  t
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


81
82
83
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 81

def table
  TaxonNameRelationship.arel_table
end

- (String) where_sql

Returns:

  • (String)


74
75
76
77
78
# File 'lib/queries/taxon_name_relationships_filter_query.rb', line 74

def where_sql
  clause = or_clauses
  clause = clause.and(and_clauses) if and_clauses
  clause.to_sql
end