class Spieker::LinkValidator

Constants

Public Class Methods

new(link, origin) click to toggle source
# File lib/spieker/link_validator.rb, line 4
def initialize(link, origin)
  @link = link
  @origin = origin
end

Public Instance Methods

valid?() click to toggle source
# File lib/spieker/link_validator.rb, line 9
def valid?
  assertions.all? { |assert| send(assert) }
end

Private Instance Methods

assert_is_local() click to toggle source
# File lib/spieker/link_validator.rb, line 19
def assert_is_local
  link =~ LOCAL_LINK_REGEX ||
    begin
      URI.parse(link).hostname == origin.hostname
    rescue
      false
    end
end
assert_is_not_data() click to toggle source
# File lib/spieker/link_validator.rb, line 40
def assert_is_not_data
  link !~ /^data/
end
assert_is_not_email() click to toggle source
# File lib/spieker/link_validator.rb, line 28
def assert_is_not_email
  link !~ /mailto/
end
assert_is_not_javascript() click to toggle source
# File lib/spieker/link_validator.rb, line 32
def assert_is_not_javascript
  link !~ /javascript/
end
assert_is_not_pdf() click to toggle source
# File lib/spieker/link_validator.rb, line 36
def assert_is_not_pdf
  link !~ /\bpdf\b/
end
assertions() click to toggle source
# File lib/spieker/link_validator.rb, line 15
def assertions
  private_methods.select { |m| m.to_s.start_with?('assert_') }
end
origin() click to toggle source
# File lib/spieker/link_validator.rb, line 48
def origin
  URI.parse @origin.start_with?('http') ? @origin : 'http://' + @origin
end