Class: AhoyCaptain::SourceQuery

Inherits:
ApplicationQuery show all
Defined in:
app/queries/ahoy_captain/source_query.rb

Instance Attribute Summary

Attributes inherited from ApplicationQuery

#params

Instance Method Summary collapse

Methods inherited from ApplicationQuery

call, inherited, #initialize, #inspect

Constructor Details

This class inherits a constructor from AhoyCaptain::ApplicationQuery

Instance Method Details

#buildObject



3
4
5
6
7
8
# File 'app/queries/ahoy_captain/source_query.rb', line 3

def build
  visit_query.select("substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)') as referring_domain, count(substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')) as count, sum(count(substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)'))) OVER() as total_count")
             .where.not(referring_domain: nil)
             .group("substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')")
             .order(Arel.sql "count(substring(referring_domain from '(?:.*://)?(?:www\.)?([^/?]*)')) desc")
end