Class: Queries::TaxonNameClassification::Filter

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/taxon_name_classification/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.

Parameters:

  • params (Params)


21
22
23
24
25
# File 'lib/queries/taxon_name_classification/filter.rb', line 21

def initialize(params)
  @taxon_name_id = params[:taxon_name_id]
  @taxon_name_classification_type = params[:taxon_name_classification_type]
  @taxon_name_classification_set = params[:taxon_name_classification_set]
end

Instance Attribute Details

#taxon_name_classification_setObject

Parameters:

  • taxon_name_classification_set (Array, String, nil)

    one or more of

    'validating',
    `invalidating`,
    `exceptions`
    


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

def taxon_name_classification_set
  @taxon_name_classification_set
end

#taxon_name_classification_typeObject

Parameters:

  • taxon_name_classification_type (String, Array, nil)

    the full class name like 'TaxonNameClassification::..etc.', or an Array of them



11
12
13
# File 'lib/queries/taxon_name_classification/filter.rb', line 11

def taxon_name_classification_type
  @taxon_name_classification_type
end

#taxon_name_idObject

Parameters:

  • taxon_name_id (String, Array, nil)

    Match all TaxonNameClassifications a taxon_name_id(s)



7
8
9
# File 'lib/queries/taxon_name_classification/filter.rb', line 7

def taxon_name_id
  @taxon_name_id
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


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

def all
  a = and_clauses
  # b = merge_clauses

  q = nil 
  if a
    q = ::TaxonNameClassification.where(a)
  else
    q = ::TaxonNameClassification.all
  end

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

#and_clausesObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/queries/taxon_name_classification/filter.rb', line 72

def and_clauses
  clauses = []

  clauses += [
    taxon_name_id_facet,
    taxon_name_classification_type_facet,
    taxon_name_classification_set_facet,
  ].compact

  return nil if clauses.empty?

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

#classification_typesArray

Returns:

  • (Array)


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/queries/taxon_name_classification/filter.rb', line 45

def classification_types
  return [] if taxon_name_classification_set.empty?
  t = []

  taxon_name_classification_set.each do |i|
    t += TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID if i == 'invalidating'
    t += TAXON_NAME_CLASS_NAMES_VALID if i == 'validating'
    t += EXCEPTED_FORM_TAXON_NAME_CLASSIFICATIONS if i == 'exceptions'
  end
  t
end

#tableArel::Table

Returns:

  • (Arel::Table)


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

def table
  ::TaxonNameClassification.arel_table
end

#taxon_name_classification_set_facetObject



57
58
59
60
# File 'lib/queries/taxon_name_classification/filter.rb', line 57

def taxon_name_classification_set_facet
  return nil if taxon_name_classification_set.empty?
  table[:type].eq_any(classification_types)
end

#taxon_name_classification_type_facetObject



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

def taxon_name_classification_type_facet
  return nil if taxon_name_classification_type.empty?
  table[:type].eq_any(taxon_name_classification_type)
end

#taxon_name_id_facetObject



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

def taxon_name_id_facet
  return nil if taxon_name_id.empty?
  table[:taxon_name_id].eq_any(taxon_name_id)
end