Class: CommonName::Filter

Inherits:
Queries::Query show all
Defined in:
lib/queries/common_name/filter.rb

Instance Attribute Summary (collapse)

Attributes inherited from Queries::Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Queries::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, #wildcard_wrapped_years, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (Filter) initialize(options)

Returns a new instance of Filter

Parameters:

  • options (Hash)


9
10
11
12
13
14
# File 'lib/queries/common_name/filter.rb', line 9

def initialize(options)
  @name = options[:name]
  @geographic_area_id = options[:geographic_area_id]
  @otu_id = options[:otu_id]
  @language_id = options[:language_id]
end

Instance Attribute Details

- (Object) geographic_area_id

Query variables



6
7
8
# File 'lib/queries/common_name/filter.rb', line 6

def geographic_area_id
  @geographic_area_id
end

- (Object) language_id

Query variables



6
7
8
# File 'lib/queries/common_name/filter.rb', line 6

def language_id
  @language_id
end

- (Object) name

Query variables



6
7
8
# File 'lib/queries/common_name/filter.rb', line 6

def name
  @name
end

- (Object) otu_id

Query variables



6
7
8
# File 'lib/queries/common_name/filter.rb', line 6

def otu_id
  @otu_id
end

Instance Method Details

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


55
56
57
58
59
60
61
62
# File 'lib/queries/common_name/filter.rb', line 55

def all
  a = and_clauses
  if a 
    ::CommonName.where(a).distinct
  else
    ::CommonName.none
  end
end

- (ActiveRecord::Relation?) and_clauses

Returns:

  • (ActiveRecord::Relation, nil)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/queries/common_name/filter.rb', line 37

def and_clauses
  clauses = [
      matching_otu_id,
      matching_geographic_area_id,
      matching_name,
      matching_language_id
  ].compact

  return nil if clauses.empty?

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

- (Object) matching_geographic_area_id



32
33
34
# File 'lib/queries/common_name/filter.rb', line 32

def matching_geographic_area_id
  geographic_area_id ? table[:geographic_area_id].eq(geographic_area_id) : nil
end

- (Object) matching_language_id



24
25
26
# File 'lib/queries/common_name/filter.rb', line 24

def matching_language_id
  language_id ? table[:language_id].eq(language_id) : nil
end

- (Object) matching_name



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

def matching_name
  name ? table[:name].eq(name) : nil
end

- (Object) matching_otu_id



20
21
22
# File 'lib/queries/common_name/filter.rb', line 20

def matching_otu_id
  otu_id ? table[:otu_id].eq(otu_id) : nil
end

- (Object) table



16
17
18
# File 'lib/queries/common_name/filter.rb', line 16

def table
  ::CommonName.arel_table
end