Class: Queries::Citation::Filter
- Inherits:
-
Object
- Object
- Queries::Citation::Filter
- Defined in:
- lib/queries/citation/filter.rb
Overview
!! does not inherit from base query
Instance Attribute Summary collapse
-
#citation_object_id ⇒ Object
Array, Integer.
-
#citation_object_type ⇒ Object
Array, Integer.
-
#is_original ⇒ Object
Boolean.
-
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here.
-
#source_id ⇒ Object
Array, Integer.
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation?
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_citation_object_id ⇒ Arel::Node?
- #matching_citation_object_type ⇒ Arel::Node?
- #matching_is_original ⇒ Object
- #matching_source_id ⇒ Arel::Node?
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
24 25 26 27 28 29 30 |
# File 'lib/queries/citation/filter.rb', line 24 def initialize(params) @citation_object_type = params[:citation_object_type] @citation_object_id = params[:citation_object_id] @source_id = params[:source_id] @is_original = params[:is_original] @options = params end |
Instance Attribute Details
#citation_object_id ⇒ Object
Array, Integer
17 18 19 |
# File 'lib/queries/citation/filter.rb', line 17 def citation_object_id @citation_object_id end |
#citation_object_type ⇒ Object
Array, Integer
17 18 19 |
# File 'lib/queries/citation/filter.rb', line 17 def citation_object_type @citation_object_type end |
#is_original ⇒ Object
Boolean
20 21 22 |
# File 'lib/queries/citation/filter.rb', line 20 def is_original @is_original end |
#options ⇒ Object
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 end |
#source_id ⇒ Object
Array, Integer
17 18 19 |
# File 'lib/queries/citation/filter.rb', line 17 def source_id @source_id end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
71 72 73 74 75 76 77 |
# File 'lib/queries/citation/filter.rb', line 71 def all if a = and_clauses ::Citation.where(and_clauses).distinct else ::Citation.all end end |
#and_clauses ⇒ ActiveRecord::Relation?
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/queries/citation/filter.rb', line 33 def and_clauses clauses = [ ::Queries::Annotator.annotator_params(, ::Citation), matching_citation_object_type, matching_citation_object_id, matching_source_id, matching_is_original ].compact return nil if clauses.empty? a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_citation_object_id ⇒ Arel::Node?
57 58 59 |
# File 'lib/queries/citation/filter.rb', line 57 def matching_citation_object_id citation_object_id.blank? ? nil : table[:citation_object_id].eq(citation_object_id) end |
#matching_citation_object_type ⇒ Arel::Node?
52 53 54 |
# File 'lib/queries/citation/filter.rb', line 52 def matching_citation_object_type citation_object_type.blank? ? nil : table[:citation_object_type].eq(citation_object_type) end |
#matching_is_original ⇒ Object
66 67 68 |
# File 'lib/queries/citation/filter.rb', line 66 def matching_is_original is_original.blank? ? nil : table[:is_original].eq(is_original) end |
#matching_source_id ⇒ Arel::Node?
62 63 64 |
# File 'lib/queries/citation/filter.rb', line 62 def matching_source_id source_id.blank? ? nil : table[:source_id].eq(source_id) end |
#table ⇒ Arel::Table
80 81 82 |
# File 'lib/queries/citation/filter.rb', line 80 def table ::Citation.arel_table end |