Class: Queries::CollectingEventDatesExtractorQuery
- Inherits:
- 
      Object
      
        - Object
- Queries::CollectingEventDatesExtractorQuery
 
- Includes:
- Arel::Nodes
- Defined in:
- lib/queries/collecting_event_dates_extractor_query.rb
Overview
< Queries::Query
Instance Attribute Summary collapse
- 
  
    
      #collecting_event_id  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute collecting_event_id. 
- 
  
    
      #filters  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute filters. 
- 
  
    
      #project_id  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute project_id. 
Instance Method Summary collapse
- #all ⇒ Scope
- 
  
    
      #filter_scopes  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Of all of the regexs available at this time. 
- 
  
    
      #initialize(collecting_event_id: nil, project_id: nil, filters: [])  ⇒ Integer 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Project id. 
- #regex_function(filter) ⇒ Scope
- #starting_after_id ⇒ Arel::Attribute
- #table ⇒ Arel::Table
- #verbatim_date_empty ⇒ String
- #verbatim_label_not_empty ⇒ Arel::Nodes::NamedFunction
- 
  
    
      #where_sql  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Of sql. 
Constructor Details
#initialize(collecting_event_id: nil, project_id: nil, filters: []) ⇒ Integer
Returns project id.
| 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_id ⇒ Object
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 | 
#filters ⇒ Object
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_id ⇒ Object
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
#all ⇒ Scope
| 50 51 52 | # File 'lib/queries/collecting_event_dates_extractor_query.rb', line 50 def all ::CollectingEvent.where(where_sql) end | 
#filter_scopes ⇒ String
Returns 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
| 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_id ⇒ 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 | 
#table ⇒ Arel::Table
| 45 46 47 | # File 'lib/queries/collecting_event_dates_extractor_query.rb', line 45 def table ::CollectingEvent.arel_table end | 
#verbatim_date_empty ⇒ 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_empty ⇒ 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_sql ⇒ String
Returns 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 |