Class: Queries::Download::Filter

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



12
13
14
# File 'lib/queries/download/filter.rb', line 12

def initialize(params)
  @download_type = params[:download_type]
end

Instance Attribute Details

#download_typeObject

Parameters:

  • download_type (Array. String)

    like 'Download::DwcArchive', one of the models in app/models/download



9
10
11
# File 'lib/queries/download/filter.rb', line 9

def download_type
  @download_type
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


43
44
45
46
47
48
49
# File 'lib/queries/download/filter.rb', line 43

def all
  if a = and_clauses
    ::Download.where(and_clauses)
  else
    ::Download.all
  end
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/queries/download/filter.rb', line 30

def and_clauses
  clauses = [
    download_type_facet
  ].compact

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

#download_type_facetObject



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

def download_type_facet
  return nil if download_type.nil?
  table[:type].eq_any(download_type)
end

#tableArel::Table

Returns:

  • (Arel::Table)


52
53
54
# File 'lib/queries/download/filter.rb', line 52

def table
  ::Download.arel_table
end