class Govuk::Diff::Pages::UrlChecker

Public Class Methods

new(config) click to toggle source
# File lib/govuk/diff/pages/url_checker.rb, line 5
def initialize(config)
  @config = config
  @govuk_regex = /^#{@config.domains.production}/
  @parameterised_url_regex = /\?/
  @relative_path_regex = /^\//
end

Public Instance Methods

normalize(url) click to toggle source
# File lib/govuk/diff/pages/url_checker.rb, line 25
def normalize(url)
  raise "Not GOVUK url: #{url}" unless valid?(url)
  url.sub(@govuk_regex, '')
end
production_url(url) click to toggle source
# File lib/govuk/diff/pages/url_checker.rb, line 30
def production_url(url)
  "#{@config.domains.production}#{normalize(url)}"
end
valid?(url) click to toggle source

returns true if non parameterised and a relative or govuk url

# File lib/govuk/diff/pages/url_checker.rb, line 13
def valid?(url)
  if url =~ @parameterised_url_regex # question mark denotes it has parameters - we don't want those
    false
  elsif url =~ @relative_path_regex # starts with slash - so is a path on govuk website
    true
  elsif url =~ @govuk_regex # gov uk full link
    true
  else
    false
  end
end