Class: Url

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ Url

Returns a new instance of Url.



3
4
5
6
7
# File 'lib/crawler_sample/url.rb', line 3

def initialize(values = {})
  values.each do |k, v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



2
3
4
# File 'lib/crawler_sample/url.rb', line 2

def host
  @host
end

#schemeObject

Returns the value of attribute scheme.



2
3
4
# File 'lib/crawler_sample/url.rb', line 2

def scheme
  @scheme
end

#valueObject

Returns the value of attribute value.



2
3
4
# File 'lib/crawler_sample/url.rb', line 2

def value
  @value
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/crawler_sample/url.rb', line 9

def valid?
  begin
    uri = URI.parse(self.value)
    resp = uri.kind_of?(URI::HTTP)
    return resp
  rescue URI::InvalidURIError
    return false
  end
end