Class: Queries::CollectingEventLatLongExtractorQuery

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

Overview

For example:

start_id.gt(collecting_event_id)

becomes

start_id.gt(Arel::Nodes::Quoted.new(collecting_event_id))

Arel performing automatic type casting is deprecated, and will be removed in Arel 8.0. If you are seeing this, it is because you are manually passing a value to an Arel predicate, and the `Arel::Table` object was constructed manually. The easiest way to remove this warning is to use an `Arel::Table` object returned from calling `arel_table` on an ApplicationRecord subclass.

If you're certain the value is already of the right type, change `attribute.eq(value)` to `attribute.eq (Arel::Nodes::Quoted.new(value))` (you will be able to remove that in Arel 8.0, it is only required to silence this deprecation warning).

You can also silence this warning globally by setting `$arel_silence_type_casting_deprecation` to `true`. (Do NOT do this if you are a library author)

If you are passing user input to a predicate, you must either give an appropriate type caster object to the `Arel::Table`, or manually cast the value before passing it to Arel. DEPRECATION WARNING: Passing a column to `quote` has been deprecated. It is only used for type casting, which should be handled elsewhere. See github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11 for more information. (called from where_sql at /Users/tuckerjd/src/taxonworks/lib/queries/collecting_event_lat_long_extractor_query.rb:41)

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)
  • Project_id (Integer)


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

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



32
33
34
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 32

def collecting_event_id
  @collecting_event_id
end

- (Object) filters

Returns the value of attribute filters



33
34
35
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 33

def filters
  @filters
end

- (Object) project_id

Returns the value of attribute project_id



34
35
36
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 34

def project_id
  @project_id
end

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


81
82
83
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 81

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 49

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
  q1 = "(#{all_filters.gsub('?<lat>', '').gsub('?<long>', '')})"
  q2 = ActiveRecord::Base.send(:sanitize_sql_array, ['(?)', all_filters.gsub('?<lat>', '').gsub('?<long>', '')])
  Arel.sql(q1)
end

- (Scope) regex_function(filter)

Parameters:

  • filter (String)

    key to FILTERS regex string

Returns:

  • (Scope)


105
106
107
108
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 105

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

- (Arel::Attribute) starting_after

Returns:

  • (Arel::Attribute)


98
99
100
101
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 98

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

- (Arel::Table) table

Returns:

  • (Arel::Table)


76
77
78
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 76

def table
  ::CollectingEvent.arel_table
end

- (Arel::Nodes::NamedFunction) verbatim_label_not_empty

Returns:

  • (Arel::Nodes::NamedFunction)


86
87
88
89
90
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 86

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

- (String) verbatim_lat_long_empty

Returns:

  • (String)


93
94
95
# File 'lib/queries/collecting_event_lat_long_extractor_query.rb', line 93

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

- (String) where_sql

Returns:

  • (String)


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

def where_sql
  # with_project_id.and
  # TODO: make sure you select the one of the following lines which suits your purpose: with or without
  # Verbatim_lat/long present (default: Verbatim_lat/long is empty)
  (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