Class: Queries::Citation::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/queries/citation/filter.rb

Overview

!! does not inherit from base query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Filter

Returns a new instance of Filter



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

def initialize(params)
  @citation_object_type = params[:citation_object_type]
  @citation_object_id = params[:citation_object_id]
  @source_id = params[:source_id]
  @options = params
end

Instance Attribute Details

#citation_object_idObject

Array, Integer



17
18
19
# File 'lib/queries/citation/filter.rb', line 17

def citation_object_id
  @citation_object_id
end

#citation_object_typeObject

Array, Integer



17
18
19
# File 'lib/queries/citation/filter.rb', line 17

def citation_object_type
  @citation_object_type
end

#optionsObject

General annotator options handling happens directly on the params as passed through to the controller, keep them together here



14
15
16
# File 'lib/queries/citation/filter.rb', line 14

def options
  @options
end

#source_idObject

Array, Integer



17
18
19
# File 'lib/queries/citation/filter.rb', line 17

def source_id
  @source_id
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


62
63
64
65
66
67
68
# File 'lib/queries/citation/filter.rb', line 62

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

#and_clausesActiveRecord::Relation?

Returns:

  • (ActiveRecord::Relation, nil)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/queries/citation/filter.rb', line 29

def and_clauses
  clauses = [
    ::Queries::Annotator.annotator_params(options, ::Citation),
    matching_citation_object_type,
    matching_citation_object_id,
    matching_source_id,
  ].compact

  return nil if clauses.empty?

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

#matching_citation_object_idArel::Node?

Returns:

  • (Arel::Node, nil)


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

def matching_citation_object_id
  citation_object_id.blank? ? nil : table[:citation_object_id].eq(citation_object_id)  
end

#matching_citation_object_typeArel::Node?

Returns:

  • (Arel::Node, nil)


47
48
49
# File 'lib/queries/citation/filter.rb', line 47

def matching_citation_object_type
  citation_object_type.blank? ? nil : table[:citation_object_type].eq(citation_object_type) 
end

#matching_source_idArel::Node?

Returns:

  • (Arel::Node, nil)


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

def matching_source_id
  source_id.blank? ? nil : table[:source_id].eq(source_id)  
end

#tableArel::Table

Returns:

  • (Arel::Table)


71
72
73
# File 'lib/queries/citation/filter.rb', line 71

def table
  ::Citation.arel_table
end