url_parser 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d88f4309a1787a5ed3f004e60a85e5f4a5e26765
4
- data.tar.gz: 78146dbfb19dbec7f5f9169fef026a7b2448c43d
3
+ metadata.gz: d5650a4eee893c20d6109ba81727dee86207dd9a
4
+ data.tar.gz: 2d91d7efec1239d3bfdd56fc61b36d3274a3c8bc
5
5
  SHA512:
6
- metadata.gz: 99801e22611a0d7c78b576e01aacb097c32852fa99775674524b2bf1f000988e64cb00766eaeec083ce16b0cb7c10c9b29745dff7186fca43135276e467c8a05
7
- data.tar.gz: 4df106696e71b773da7bc7e7997ac8ade0cb4002327cbb107c1b436c420373b1ce55abcd0eed67d0b328385c7d35d190bc921e5e64d264ef26c4ce7232817389
6
+ metadata.gz: 6dd4c33a39b4dcbada0f21f52551df48ca1d514860c81caf64b1aa184eacc7dc1d707f705b41f6331d79d9588ebec9ae30144df7dc4ea9c0abd223532da31328
7
+ data.tar.gz: 98edd4c481f0494f5238601053947fc86d2d7a5e02ce6fc8a537d94ef57213bcdb5fb816813761cdb6be8b9845bf7c9cd52702eadee803d97285debc0a96d9f4
@@ -1,3 +1,3 @@
1
1
  module UrlParser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/url_parser.rb CHANGED
@@ -62,6 +62,18 @@ module UrlParser
62
62
  end
63
63
  end
64
64
 
65
+ def clean!
66
+ @preserve = false
67
+ @parser = nil
68
+ @uri = nil
69
+ @url = PostRank::URI.clean(url)
70
+ self
71
+ end
72
+
73
+ def to_s
74
+ url
75
+ end
76
+
65
77
  def schemes
66
78
  Array.wrap(@schemes)
67
79
  end
@@ -136,6 +148,11 @@ module UrlParser
136
148
  end
137
149
  end
138
150
 
151
+ def join(relative_path)
152
+ joined_url = Addressable::URI.join(url, relative_path).to_s
153
+ UrlParser.new(joined_url, preserve: true)
154
+ end
155
+
139
156
  private
140
157
 
141
158
  def tag_errors
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require "rspec"
2
+ begin
3
+ require "pry"
4
+ rescue LoadError; end
2
5
 
3
6
  require "url_parser"
4
7
 
@@ -71,6 +71,31 @@ describe UrlParser do
71
71
 
72
72
  end
73
73
 
74
+ context "#clean!" do
75
+
76
+ let(:link) { 'link.to?a=b&utm_source=FeedBurner#stuff' }
77
+ let(:parser) { UrlParser.new(link, preserve: true) }
78
+
79
+ before { parser.clean! }
80
+
81
+ it "normalizes the url" do
82
+ expect(parser.url).to eq 'http://link.to/?a=b'
83
+ end
84
+
85
+ it "resets the uri" do
86
+ expect(parser.instance_variable_get(:@uri)).to be_nil
87
+ end
88
+
89
+ it "resets the parser" do
90
+ expect(parser.instance_variable_get(:@parser)).to be_nil
91
+ end
92
+
93
+ end
94
+
95
+ context "#to_s" do
96
+
97
+ end
98
+
74
99
  context "#uri" do
75
100
 
76
101
  it "returns a parsed uri" do
@@ -173,4 +198,41 @@ describe UrlParser do
173
198
 
174
199
  end
175
200
 
201
+ # Thanks to http://stackoverflow.com/a/4864170
202
+ #
203
+ context "#join" do
204
+
205
+ let(:link) { 'http://foo.com/zee/zaw/zoom.html' }
206
+
207
+ it "properly combines a url and and relative url" do
208
+ {
209
+ 'http://zork.com/' => 'http://zork.com/',
210
+ 'http://zork.com/#id' => 'http://zork.com/#id',
211
+ 'http://zork.com/bar' => 'http://zork.com/bar',
212
+ 'http://zork.com/bar#id' => 'http://zork.com/bar#id',
213
+ 'http://zork.com/bar/' => 'http://zork.com/bar/',
214
+ 'http://zork.com/bar/#id' => 'http://zork.com/bar/#id',
215
+ 'http://zork.com/bar/jim.html' => 'http://zork.com/bar/jim.html',
216
+ 'http://zork.com/bar/jim.html#id' => 'http://zork.com/bar/jim.html#id',
217
+ '/bar' => 'http://foo.com/bar',
218
+ '/bar#id' => 'http://foo.com/bar#id',
219
+ '/bar/' => 'http://foo.com/bar/',
220
+ '/bar/#id' => 'http://foo.com/bar/#id',
221
+ '/bar/jim.html' => 'http://foo.com/bar/jim.html',
222
+ '/bar/jim.html#id' => 'http://foo.com/bar/jim.html#id',
223
+ 'jim.html' => 'http://foo.com/zee/zaw/jim.html',
224
+ 'jim.html#id' => 'http://foo.com/zee/zaw/jim.html#id',
225
+ '../jim.html' => 'http://foo.com/zee/jim.html',
226
+ '../jim.html#id' => 'http://foo.com/zee/jim.html#id',
227
+ '../' => 'http://foo.com/zee/',
228
+ '../#id' => 'http://foo.com/zee/#id',
229
+ '#id' => 'http://foo.com/zee/zaw/zoom.html#id'
230
+ }.each do |relative_url, expected_result|
231
+ expect(parser.join(relative_url).to_s).to eq expected_result
232
+ end
233
+
234
+ end
235
+
236
+ end
237
+
176
238
  end
data/url_parser.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake", "~> 10"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "pry"
24
25
 
25
26
  spec.add_dependency "domainatrix", ">= 0.0.11"
26
27
  spec.add_dependency "postrank-uri", "~> 1.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Solt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-03 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: domainatrix
57
71
  requirement: !ruby/object:Gem::Requirement