Class: HrefProtocol::Sanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/href_protocol.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Sanitizer

Returns a new instance of Sanitizer.



5
6
7
# File 'lib/href_protocol.rb', line 5

def initialize(value)
  @value = value
end

Instance Method Details

#hrefObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/href_protocol.rb', line 9

def href
  href = @value.to_s.strip

  return @value if href.empty?

  if href =~ %r{\A(/|(https?|ftp|mailto):)}i
    href
  else
    "http://#{href}"
  end
end