Class: Saper::Items::URL

Inherits:
Saper::Item show all
Defined in:
lib/saper/items/url.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Saper::Item

#==, [], exists?, inherited, #serialize, subclasses, try, #type, type

Constructor Details

#initialize(url) ⇒ URL

TODO:

Returns a new instance of URL


26
27
28
# File 'lib/saper/items/url.rb', line 26

def initialize(url)
  @url = url
end

Class Method Details

.new(item) ⇒ Object

TODO:

6
7
8
9
10
11
12
13
14
15
# File 'lib/saper/items/url.rb', line 6

def self.new(item)
  super case item
  when Text
    parse(item.to_s)
  when String
    parse(item)
  else
    raise(Errors::InvalidItem, item)
  end
end

.parse(string) ⇒ Object

TODO:

18
19
20
21
22
23
# File 'lib/saper/items/url.rb', line 18

def self.parse(string)
  unless string =~ /^#{URI::regexp}$/
    raise(Errors::InvalidItem, string)
  end
  string
end

Instance Method Details

#to_nativeObject

TODO:

36
37
38
# File 'lib/saper/items/url.rb', line 36

def to_native
  @url
end

#to_sObject

TODO:

31
32
33
# File 'lib/saper/items/url.rb', line 31

def to_s
  to_native
end