Class: Queries::Confidence::Filter
- Inherits:
-
Object
- Object
- Queries::Confidence::Filter
- Defined in:
- lib/queries/confidence/filter.rb
Overview
!! does not inherit from base query
Instance Attribute Summary collapse
-
#confidence_level_id ⇒ Object
Array, Integer.
-
#confidence_object_type ⇒ Object
Array, Integer.
-
#object_global_id ⇒ Object
Array, Integer.
-
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here.
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_confidence_level_id ⇒ Arel::Node?
- #matching_confidence_object_type ⇒ Arel::Node?
-
#matching_object ⇒ Arel::Node?
TODO: Dry.
-
#object_for ⇒ ActiveRecord object?
TODO: DRY.
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
19 20 21 22 23 24 |
# File 'lib/queries/confidence/filter.rb', line 19 def initialize(params) @confidence_level_id = [params[:confidence_level_id]].flatten.compact @object_global_id = params[:object_global_id] @confidence_object_type = params[:confidence_object_type] @options = params end |
Instance Attribute Details
#confidence_level_id ⇒ Object
Array, Integer
16 17 18 |
# File 'lib/queries/confidence/filter.rb', line 16 def confidence_level_id @confidence_level_id end |
#confidence_object_type ⇒ Object
Array, Integer
16 17 18 |
# File 'lib/queries/confidence/filter.rb', line 16 def confidence_object_type @confidence_object_type end |
#object_global_id ⇒ Object
Array, Integer
16 17 18 |
# File 'lib/queries/confidence/filter.rb', line 16 def object_global_id @object_global_id end |
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here
13 14 15 |
# File 'lib/queries/confidence/filter.rb', line 13 def @options end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
77 78 79 80 81 82 83 |
# File 'lib/queries/confidence/filter.rb', line 77 def all if a = and_clauses ::Confidence.where(and_clauses).distinct else ::Confidence.all end end |
#and_clauses ⇒ ActiveRecord::Relation
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/queries/confidence/filter.rb', line 27 def and_clauses clauses = [ ::Queries::Annotator.annotator_params(, ::Confidence), matching_confidence_level_id, matching_confidence_object_type, matching_object, ].compact return nil if clauses.empty? a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_confidence_level_id ⇒ Arel::Node?
67 68 69 |
# File 'lib/queries/confidence/filter.rb', line 67 def matching_confidence_level_id !confidence_level_id.blank? ? table[:confidence_level_id].eq_any(confidence_level_id) : nil end |
#matching_confidence_object_type ⇒ Arel::Node?
72 73 74 |
# File 'lib/queries/confidence/filter.rb', line 72 def matching_confidence_object_type !confidence_object_type.blank? ? table[:confidence_object_type].eq(confidence_object_type) : nil end |
#matching_object ⇒ Arel::Node?
TODO: Dry
56 57 58 59 60 61 62 63 64 |
# File 'lib/queries/confidence/filter.rb', line 56 def matching_object if o = object_for table["confidence_object_id"].eq(o.id).and( table["confidence_object_type"].eq(o..class.name) ) else nil end end |
#object_for ⇒ ActiveRecord object?
TODO: DRY
46 47 48 49 50 51 52 |
# File 'lib/queries/confidence/filter.rb', line 46 def object_for if o = GlobalID::Locator.locate(object_global_id) o else nil end end |
#table ⇒ Arel::Table
86 87 88 |
# File 'lib/queries/confidence/filter.rb', line 86 def table ::Confidence.arel_table end |