Class: Queries::CollectingEventDatesExtractorQuery

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

Overview

< Queries::Query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collecting_event_id: nil, project_id: nil, filters: []) ⇒ Integer

Returns project id.

Parameters:

  • collecting_event_id (Integer) (defaults to: nil)
  • project_id (Integer) (defaults to: nil)
  • filters, (Array)

    array of symbolized filter names



13
14
15
16
17
18
19
20
# File 'lib/queries/collecting_event_dates_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

#collecting_event_idObject

Returns the value of attribute collecting_event_id.



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

def collecting_event_id
  @collecting_event_id
end

#filtersObject

Returns the value of attribute filters.



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

def filters
  @filters
end

#project_idObject

Returns the value of attribute project_id.



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

def project_id
  @project_id
end

Instance Method Details

#allScope

Returns:

  • (Scope)


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

def all
  ::CollectingEvent.where(where_sql)
end

#filter_scopesString

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_dates_extractor_query.rb', line 23

def filter_scopes
  if filters.blank?
    filter_keys = Utilities::Dates::REGEXP_DATES.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('?<year>', '').gsub('?<month>', '')})")
end

#regex_function(filter) ⇒ Scope

Parameters:

  • filter, (String)

    key to FILTERS regex string

Returns:

  • (Scope)


73
74
75
76
# File 'lib/queries/collecting_event_dates_extractor_query.rb', line 73

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

#starting_after_idArel::Attribute

Returns:

  • (Arel::Attribute)


66
67
68
69
# File 'lib/queries/collecting_event_dates_extractor_query.rb', line 66

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

#tableArel::Table

Returns:

  • (Arel::Table)


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

def table
  ::CollectingEvent.arel_table
end

#verbatim_date_emptyString

Returns:

  • (String)


61
62
63
# File 'lib/queries/collecting_event_dates_extractor_query.rb', line 61

def verbatim_date_empty
  Arel.sql('(verbatim_date is null)')
end

#verbatim_label_not_emptyArel::Nodes::NamedFunction

Returns:

  • (Arel::Nodes::NamedFunction)


55
56
57
58
# File 'lib/queries/collecting_event_dates_extractor_query.rb', line 55

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

#where_sqlString

Returns of sql.

Returns:

  • (String)

    of sql



39
40
41
42
# File 'lib/queries/collecting_event_dates_extractor_query.rb', line 39

def where_sql
  (verbatim_label_not_empty).and(verbatim_date_empty).and(starting_after_id).and(filter_scopes).to_sql
  # (verbatim_label_not_empty).and(starting_after_id).and(filter_scopes).to_sql
end