Class: DwcaHunter::Url
- Inherits:
-
Object
- Object
- DwcaHunter::Url
- Defined in:
- lib/dwca_hunter/url.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#net_http ⇒ Object
readonly
Returns the value of attribute net_http.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #content_length ⇒ Object
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
-
#valid? ⇒ Boolean
confirm that the passed in URL is valid and responses with a proper code.
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
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/dwca_hunter/url.rb', line 4 def header @header end |
#net_http ⇒ Object (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 |
#path ⇒ Object (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_length ⇒ Object
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
15 16 17 |
# File 'lib/dwca_hunter/url.rb', line 15 def valid? @header && ['200','301','302'].include?(@header.code) end |