Class: Queries::Observation::Filter
- Inherits:
-
Object
- Object
- Queries::Observation::Filter
- Defined in:
- lib/queries/observation/filter.rb
Overview
!! does not inherit from base query
Instance Attribute Summary collapse
-
#character_state_id ⇒ Object
Returns the value of attribute character_state_id.
-
#collection_object_id ⇒ Object
Returns the value of attribute collection_object_id.
-
#descriptor_id ⇒ Object
Returns the value of attribute descriptor_id.
-
#observation_object_global_id ⇒ Object
Returns the value of attribute observation_object_global_id.
-
#otu_id ⇒ Object
Returns the value of attribute otu_id.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_character_state_id ⇒ Arel::Node?
- #matching_collection_object_id ⇒ Arel::Node?
- #matching_descriptor_id ⇒ Arel::Node?
- #matching_observation_object_global_id ⇒ Arel::Node?
- #matching_otu_id ⇒ Arel::Node?
- #matching_type ⇒ Arel::Node?
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
9 10 11 12 13 14 15 16 17 |
# File 'lib/queries/observation/filter.rb', line 9 def initialize(params) @otu_id = params[:otu_id] @collection_object_id = params[:collection_object_id] @observation_object_global_id = params[:observation_object_global_id] @descriptor_id = params[:descriptor_id] @type = params[:type] @character_state_id = params[:character_state_id] end |
Instance Attribute Details
#character_state_id ⇒ Object
Returns the value of attribute character_state_id.
7 8 9 |
# File 'lib/queries/observation/filter.rb', line 7 def character_state_id @character_state_id end |
#collection_object_id ⇒ Object
Returns the value of attribute collection_object_id.
7 8 9 |
# File 'lib/queries/observation/filter.rb', line 7 def collection_object_id @collection_object_id end |
#descriptor_id ⇒ Object
Returns the value of attribute descriptor_id.
7 8 9 |
# File 'lib/queries/observation/filter.rb', line 7 def descriptor_id @descriptor_id end |
#observation_object_global_id ⇒ Object
Returns the value of attribute observation_object_global_id.
7 8 9 |
# File 'lib/queries/observation/filter.rb', line 7 def observation_object_global_id @observation_object_global_id end |
#otu_id ⇒ Object
Returns the value of attribute otu_id.
7 8 9 |
# File 'lib/queries/observation/filter.rb', line 7 def otu_id @otu_id end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/queries/observation/filter.rb', line 7 def type @type end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
92 93 94 95 96 97 98 |
# File 'lib/queries/observation/filter.rb', line 92 def all if a = and_clauses ::Observation.where(and_clauses) else ::Observation.none end end |
#and_clauses ⇒ ActiveRecord::Relation
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/queries/observation/filter.rb', line 20 def and_clauses clauses = [ matching_descriptor_id, matching_otu_id, matching_collection_object_id, matching_observation_object_global_id, matching_character_state_id ].compact a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_character_state_id ⇒ Arel::Node?
57 58 59 |
# File 'lib/queries/observation/filter.rb', line 57 def matching_character_state_id character_state_id.blank? ? nil : table[:character_state_id].eq(character_state_id) end |
#matching_collection_object_id ⇒ Arel::Node?
67 68 69 |
# File 'lib/queries/observation/filter.rb', line 67 def matching_collection_object_id collection_object_id.blank? ? nil : table[:collection_object_id].eq(collection_object_id) end |
#matching_descriptor_id ⇒ Arel::Node?
77 78 79 |
# File 'lib/queries/observation/filter.rb', line 77 def matching_descriptor_id descriptor_id.blank? ? nil : table[:descriptor_id].eq(descriptor_id) end |
#matching_observation_object_global_id ⇒ Arel::Node?
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/queries/observation/filter.rb', line 37 def matching_observation_object_global_id if observation_object_global_id.blank? nil else # TODO - make a hash method to parameterize these values o = GlobalID::Locator.locate(observation_object_global_id) case o..class.name when 'Otu' table[:otu_id].eq(o.id) when 'CollectionObject' table[:collection_object_id].eq(o.id) else return nil end end end |
#matching_otu_id ⇒ Arel::Node?
62 63 64 |
# File 'lib/queries/observation/filter.rb', line 62 def matching_otu_id otu_id.blank? ? nil : table[:otu_id].eq(otu_id) end |
#matching_type ⇒ Arel::Node?
72 73 74 |
# File 'lib/queries/observation/filter.rb', line 72 def matching_type type.blank? ? nil : table[:type].eq(type) end |
#table ⇒ Arel::Table
101 102 103 |
# File 'lib/queries/observation/filter.rb', line 101 def table ::Observation.arel_table end |