Class: Queries::Observation::Filter

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

Overview

!! does not inherit from base query

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Filter) initialize(params)

Returns a new instance of Filter



16
17
18
19
20
21
22
23
24
25
# File 'lib/queries/observation/filter.rb', line 16

def initialize(params)
  @otu_id = params[:otu_id]
  @observation_object_global_id = params[:observation_object_global_id]
  @collection_object_id = params[:collection_object_id]
  @descriptor_id = params[:descriptor_id]
  @character_state_id = params[:character_state_id]
  @type = params[:type]
 
  @options = params 
end

Instance Attribute Details

- (Object) character_state_id

Params specific to AlternateValue



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

def character_state_id
  @character_state_id
end

- (Object) collection_object_id

Params specific to AlternateValue



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

def collection_object_id
  @collection_object_id
end

- (Object) descriptor_id

Params specific to AlternateValue



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

def descriptor_id
  @descriptor_id
end

- (Object) observation_object_global_id

Params specific to AlternateValue



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

def observation_object_global_id
  @observation_object_global_id
end

- (Object) options

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



11
12
13
# File 'lib/queries/observation/filter.rb', line 11

def options
  @options
end

- (Object) otu_id

Params specific to AlternateValue



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

def otu_id
  @otu_id
end

- (Object) type

Params specific to AlternateValue



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

def type
  @type
end

Instance Method Details

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


83
84
85
86
87
88
89
# File 'lib/queries/observation/filter.rb', line 83

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

- (ActiveRecord::Relation) and_clauses

Returns:

  • (ActiveRecord::Relation)


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

def and_clauses
  clauses = [
    matching_descriptor_id,
    matching_observation_object_global_id
  ].compact

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

- (Arel::Node?) matching_character_state_id

Returns:

  • (Arel::Node, nil)


73
74
75
# File 'lib/queries/observation/filter.rb', line 73

def matching_character_state_id
  character_state_id.blank? ? nil : table[:character_state_id].eq(character_state_id) 
end

- (Arel::Node?) matching_descriptor_id

Returns:

  • (Arel::Node, nil)


68
69
70
# File 'lib/queries/observation/filter.rb', line 68

def matching_descriptor_id
  descriptor_id.blank? ? nil : table[:descriptor_id].eq(descriptor_id) 
end

- (Arel::Node?) matching_observation_object_global_id

Returns:

  • (Arel::Node, nil)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/queries/observation/filter.rb', line 42

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.metamorphosize.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

- (Arel::Node?) matching_otu_id

Returns:

  • (Arel::Node, nil)


78
79
80
# File 'lib/queries/observation/filter.rb', line 78

def matching_otu_id
  otu_id.blank? ? nil : table[:otu_id].eq(otu_id) 
end

- (Arel::Node?) matching_type

Returns:

  • (Arel::Node, nil)


62
63
64
# File 'lib/queries/observation/filter.rb', line 62

def matching_type
  type.blank? ? nil : table[:type].eq(type) 
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


92
93
94
# File 'lib/queries/observation/filter.rb', line 92

def table
  ::Observation.arel_table
end