Class: ScreenedUrl

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ScreeningModel
Defined in:
app/models/screened_url.rb

Overview

For now, nothing is done. We’re just collecting the data and will decide what to do with it later.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ScreeningModel

#action_name=, #record_match!, #set_default_action

Class Method Details

.find_match(url) ⇒ Object



27
28
29
# File 'app/models/screened_url.rb', line 27

def self.find_match(url)
  find_by_url normalize_url(url)
end

.normalize_url(url) ⇒ Object



31
32
33
34
35
36
# File 'app/models/screened_url.rb', line 31

def self.normalize_url(url)
  normalized = url.gsub(%r{http(s?)://}i, "")
  normalized.gsub!(%r{(/)+\z}, "") # trim trailing slashes
  normalized.gsub!(%r{\A([^/]+)(?:/)?}) { |m| m.downcase } # downcase the domain part of the url
  normalized
end

.watch(url, domain, opts = {}) ⇒ Object



23
24
25
# File 'app/models/screened_url.rb', line 23

def self.watch(url, domain, opts = {})
  find_match(url) || create(opts.slice(:action_type, :ip_address).merge(url: url, domain: domain))
end

Instance Method Details

#normalizeObject



18
19
20
21
# File 'app/models/screened_url.rb', line 18

def normalize
  self.url = ScreenedUrl.normalize_url(self.url) if self.url
  self.domain = self.domain.downcase.sub(/\Awww\./, "") if self.domain
end