url-resolver 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db7a7220f82e0585a2dd0ab26335e40300368f73
4
- data.tar.gz: 9fcd01d51c24a1ba01649bb1b249b10acd39b9cf
3
+ metadata.gz: c4d3d0a1522053daf7c576fc4916b6b1348ccde7
4
+ data.tar.gz: ec934c75d42624fa974e0a3f45d9b550d923095a
5
5
  SHA512:
6
- metadata.gz: b4b434d0f90569dd9b38c5042925305131048a0c1b68517067a147c519a6e3ff3cb7379f84f1e1092708039ac8fd03b30faf263fb654fc052c493318b2b6ba26
7
- data.tar.gz: de5b9e0f5137b54a1330ef73849714e2df793a12b435ebd8b34ab6de0975f42698c30a23e5f4df0271538ba86b28fc985474c4526a1011e371d4a59b9cadd5e2
6
+ metadata.gz: 537d12ab6ae16036806c35c8e945084a47840fb1b390525140d568b722578558a99ef44cf1f7b5a767d73fe8806908ade75dcfe8e0fed410a5bb845fc6d0920a
7
+ data.tar.gz: 7be23d8465e2fc600473dbe28af380c299272751eeba2b43597a57f7bd21db6d70622e5614529e7ec62fbe33a61e158d56ac6f1ad3f387310fabf056b53dc26b
data/README.md CHANGED
@@ -2,8 +2,66 @@
2
2
  [![Code Climate](https://codeclimate.com/github/alexpchin/url-resolver/badges/gpa.svg)](https://codeclimate.com/github/alexpchin/url-resolver)
3
3
  [![Test Coverage](https://codeclimate.com/github/alexpchin/url-resolver/badges/coverage.svg)](https://codeclimate.com/github/alexpchin/url-resolver)
4
4
 
5
- ## Installation
5
+ ## UPDATE
6
+ I've noticed from this [stackoverflow article](http://stackoverflow.com/questions/4861517/getting-the-absolute-url-when-extracting-links) that you can actually use Ruby's URI library to resolve paths:
7
+
8
+ ```
9
+ absolute_uri = URI.join(page_url, href).to_s
10
+ ```
11
+
12
+ This gem was created quickly as part of another project and I missed this fact.
13
+
14
+ ```
15
+ require 'uri'
6
16
 
17
+ # The URL of the page with the links
18
+ page_url = 'http://foo.com/zee/zaw/zoom.html'
19
+
20
+ # A variety of links to test.
21
+ hrefs = %w[
22
+ http://zork.com/ http://zork.com/#id
23
+ http://zork.com/bar http://zork.com/bar#id
24
+ http://zork.com/bar/ http://zork.com/bar/#id
25
+ http://zork.com/bar/jim.html http://zork.com/bar/jim.html#id
26
+ /bar /bar#id
27
+ /bar/ /bar/#id
28
+ /bar/jim.html /bar/jim.html#id
29
+ jim.html jim.html#id
30
+ ../jim.html ../jim.html#id
31
+ ../ ../#id
32
+ #id
33
+ ]
34
+
35
+ hrefs.each do |href|
36
+ root_href = URI.join(page_url,href).to_s
37
+ puts "%-32s -> %s" % [ href, root_href ]
38
+ end
39
+ #=> http://zork.com/ -> http://zork.com/
40
+ #=> http://zork.com/#id -> http://zork.com/#id
41
+ #=> http://zork.com/bar -> http://zork.com/bar
42
+ #=> http://zork.com/bar#id -> http://zork.com/bar#id
43
+ #=> http://zork.com/bar/ -> http://zork.com/bar/
44
+ #=> http://zork.com/bar/#id -> http://zork.com/bar/#id
45
+ #=> http://zork.com/bar/jim.html -> http://zork.com/bar/jim.html
46
+ #=> http://zork.com/bar/jim.html#id -> http://zork.com/bar/jim.html#id
47
+ #=> /bar -> http://foo.com/bar
48
+ #=> /bar#id -> http://foo.com/bar#id
49
+ #=> /bar/ -> http://foo.com/bar/
50
+ #=> /bar/#id -> http://foo.com/bar/#id
51
+ #=> /bar/jim.html -> http://foo.com/bar/jim.html
52
+ #=> /bar/jim.html#id -> http://foo.com/bar/jim.html#id
53
+ #=> jim.html -> http://foo.com/zee/zaw/jim.html
54
+ #=> jim.html#id -> http://foo.com/zee/zaw/jim.html#id
55
+ #=> ../jim.html -> http://foo.com/zee/jim.html
56
+ #=> ../jim.html#id -> http://foo.com/zee/jim.html#id
57
+ #=> ../ -> http://foo.com/zee/
58
+ #=> ../#id -> http://foo.com/zee/#id
59
+ #=> #id -> http://foo.com/zee/zaw/zoom.html#id
60
+ ```
61
+
62
+ So consider this gem as deprecated.
63
+
64
+ ## Installation
7
65
  Add this line to your application's Gemfile:
8
66
 
9
67
  ```ruby
@@ -23,7 +81,7 @@ Or install it yourself as:
23
81
  To resolve a partial file path use:
24
82
 
25
83
  ```
26
- UrlResolver::resolve(url, path_to_resolve)
84
+ UrlResolver.resolve(url, path_to_resolve)
27
85
  ```
28
86
 
29
87
  ## Contributing
@@ -4,22 +4,21 @@ require "uri"
4
4
  module UrlResolver
5
5
 
6
6
  def self.resolve(url=nil, path_to_resolve=nil)
7
- raise ArgumentError, "You need to provide a root url." if url.nil?
8
- raise ArgumentError, "You need to provide a path to resolve." if path_to_resolve.nil?
7
+ URI.join(url, path_to_resolve).to_s
9
8
 
10
- if !path_to_resolve.include?("http")
11
- if path_to_resolve.include?("//")
12
- "http:#{path_to_resolve}"
13
- else
14
- URI.join(url, path_to_resolve).to_s
15
- end
16
- else
17
- path_to_resolve
18
- end
19
- end
9
+ ## Deprecated
10
+ # raise ArgumentError, "You need to provide a root url." if url.nil?
11
+ # raise ArgumentError, "You need to provide a path to resolve." if path_to_resolve.nil?
20
12
 
21
- end
13
+ # if !path_to_resolve.include?("http")
14
+ # if path_to_resolve.include?("//")
15
+ # "http:#{path_to_resolve}"
16
+ # else
17
+ # URI.join(url, path_to_resolve).to_s
18
+ # end
19
+ # else
20
+ # path_to_resolve
21
+ # end
22
+ end
22
23
 
23
- # Note to self
24
- # Could use Regex at some point
25
- # [/^http/], [/^\/\//]
24
+ end
@@ -1,3 +1,3 @@
1
1
  module UrlResolver
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url-resolver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chin