Class: Queries::CollectingEventLatLongExtractorQuery

Inherits:
Object
  • Object
show all
Includes:
Arel::Nodes
Defined in:
lib/queries/collecting_event_lat_long_extractor_query.rb

Overview

< Queries::Query

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CollectingEventLatLongExtractorQuery) initialize(collecting_event_id: nil, project_id: nil, filters: [])

Returns a new instance of CollectingEventLatLongExtractorQuery

Parameters:

  • collecting_event_id (Integer)
  • project_id (Integer)
  • of (Array)

    symbolized filter names

  • filters (Object)


13
14
15
16
17
18
19
20
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 13

def initialize(collecting_event_id: nil, project_id: nil, filters: [])

  collecting_event_id = 0 if collecting_event_id.nil?

  @collecting_event_id = collecting_event_id
  @filters             = filters
  @project_id         = project_id
end

Instance Attribute Details

- (Object) collecting_event_id

Returns the value of attribute collecting_event_id



5
6
7
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 5

def collecting_event_id
  @collecting_event_id
end

- (Object) filters

Returns the value of attribute filters



6
7
8
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 6

def filters
  @filters
end

- (Object) project_id

Returns the value of attribute project_id



7
8
9
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 7

def project_id
  @project_id
end

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


50
51
52
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 50

def all
  CollectingEvent.where(where_sql)
end

- (String) filter_scopes

Returns of all of the regexs available at this time

Returns:

  • (String)

    of all of the regexs available at this time



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 23

def filter_scopes
  if filters.blank?
    filter_keys = Utilities::Geo::REGEXP_COORD.keys.compact
  else
    filter_keys = filters
  end

  all_filters = filter_keys.collect do |kee|
    # attach 'verbatim_label ~ ' to each regex
    regex_function(kee)
  end.join(' OR ')
  # remove the names from the named groups: these don't work for sql regexs
  Arel.sql("(#{all_filters.gsub('?<lat>', '').gsub('?<long>', '')})")
end

- (Scope) regex_function(filter)

Parameters:

  • key (String)

    to FILTERS regex string

Returns:

  • (Scope)


70
71
72
73
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 70

def regex_function(filter)
  regex = Utilities::Geo::REGEXP_COORD[filter][:reg].to_s.gsub('(?i-mx:', '').chomp(')')
  "verbatim_label ~* '" + regex + "'"
end

- (Object) starting_after



63
64
65
66
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 63

def starting_after
  start_id = Arel::Attribute.new(Arel::Table.new(:collecting_events), :id)
  start_id.gt(collecting_event_id)
end

- (Object) table



45
46
47
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 45

def table
  CollectingEvent.arel_table
end

- (Object) verbatim_label_not_empty



54
55
56
57
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 54

def verbatim_label_not_empty
  vl = Arel::Attribute.new(Arel::Table.new(:collecting_events), :verbatim_label)
  Arel::Nodes::NamedFunction.new('length', [vl]).gt(0)
end

- (Object) verbatim_lat_long_empty



59
60
61
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 59

def verbatim_lat_long_empty
  Arel.sql('(verbatim_latitude is null or verbatim_longitude is null)')
end

- (Object) where_sql



38
39
40
41
42
43
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 38

def where_sql
  # with_project_id.and
  # TODO: make sure you select the one of the following which suits your purpose: with or without Verbatim_lat/long preset
  (verbatim_label_not_empty).and(verbatim_lat_long_empty).and(starting_after).and(filter_scopes).to_sql
  # (verbatim_label_not_empty).and(starting_after).and(filter_scopes).to_sql
end