Class: DwcaHunter::Url

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Url

Returns a new instance of Url.



6
7
8
9
10
11
12
# File 'lib/dwca_hunter/url.rb', line 6

def initialize(url)
  @url = url
  @parsed_url = URI.parse(url.strip)
  @path = @parsed_url.path == '' ? '/' : @parsed_url.path
  @net_http = Net::HTTP.new(@parsed_url.host, @parsed_url.port)
  @header = get_header
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



4
5
6
# File 'lib/dwca_hunter/url.rb', line 4

def header
  @header
end

#net_httpObject (readonly)

Returns the value of attribute net_http.



4
5
6
# File 'lib/dwca_hunter/url.rb', line 4

def net_http
  @net_http
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/dwca_hunter/url.rb', line 4

def path
  @path
end

Instance Method Details

#content_lengthObject



19
20
21
# File 'lib/dwca_hunter/url.rb', line 19

def content_length
  header ? header.content_length : nil
end

#valid?Boolean

confirm that the passed in URL is valid and responses with a proper code

Returns:

  • (Boolean)


15
16
17
# File 'lib/dwca_hunter/url.rb', line 15

def valid?
    @header && ['200','301','302'].include?(@header.code)
end