iri 0.2.0 → 0.3.0

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/iri.gemspec +3 -2
  4. data/lib/iri.rb +35 -3
  5. data/test/test_iri.rb +14 -0
  6. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12449f264a53cb485147418a1dac3bf592d6739bc9907a9150c742d67f0cea67
4
- data.tar.gz: 47b3d56c0cf5f9b613fdb4902c98bd385cce90450271e9256ec5cab8ce2cfdfc
3
+ metadata.gz: 8673c781f1957a3ae681e9b324fb65331b0d2fd3790256f02b7ca63ca97e543e
4
+ data.tar.gz: c32ca8b48268204469d8a8aa870aa73c7cbae81e74f767863e34f6547dab60ec
5
5
  SHA512:
6
- metadata.gz: f4aa33c7601a7f6ea0f06e14a091d644efd48ee821198fedecf78bedbb34adba049d203cd2466f7f2562ed3344ea8d6a7e5462732c56c36872ac343611a25f29
7
- data.tar.gz: 372918b261d96aa75a6c8f813ee315e7dc9a1a32e31343b5bbd2d54b325726771f5650bd86a7a87d76204300a19a20b31523fdc79a557b9bdb319d2a9cab2ce4
6
+ metadata.gz: 74d0e96a473993791365dbd5e35239effab3d13cb8b0d51ed395a5475d040c1a5fc980ae1900e4c8f8218fc3fd4b712d6f7e8b38fa67af1590d713f0db061e98
7
+ data.tar.gz: 8d761157337ea934988ca0ceca6478381c6d3c57c475c73940809a9def8ce0be7210fb2af049d9ded1e6977db846856be52747573ecb782d1519afcbe9c6ef82
data/README.md CHANGED
@@ -24,6 +24,8 @@ url = Iri.new('http://google.com/')
24
24
  .to_s # convert it to a string
25
25
  ```
26
26
 
27
+ The full list of methods is [here](https://www.rubydoc.info/github/yegor256/iri/master/Iri).
28
+
27
29
  Install it:
28
30
 
29
31
  ```bash
data/iri.gemspec CHANGED
@@ -31,10 +31,11 @@ Gem::Specification.new do |s|
31
31
  s.rubygems_version = '2.5'
32
32
  s.required_ruby_version = '>=2.5'
33
33
  s.name = 'iri'
34
- s.version = '0.2.0'
34
+ s.version = '0.3.0'
35
35
  s.license = 'MIT'
36
36
  s.summary = 'Simple Immutable Ruby URI Builder'
37
- s.description = 'Simple Immutable Ruby URI Builder'
37
+ s.description = 'Class Iri helps you build a URI and then modify its \
38
+ parts via a simple fluent interface.'
38
39
  s.authors = ['Yegor Bugayenko']
39
40
  s.email = 'yegor256@gmail.com'
40
41
  s.homepage = 'http://github.com/yegor256/iri'
data/lib/iri.rb CHANGED
@@ -46,18 +46,32 @@ require 'cgi'
46
46
  # License:: MIT
47
47
  class Iri
48
48
  # Makes a new object.
49
- def initialize(uri)
49
+ #
50
+ # You can even ignore the argument, which will produce an empty URI.
51
+ def initialize(uri = '')
50
52
  @uri = URI(uri)
51
53
  end
52
54
 
55
+ # Convert it to a string.
53
56
  def to_s
54
57
  @uri.to_s
55
58
  end
56
59
 
60
+ # Convert it to an object of class +URI+.
57
61
  def to_uri
58
62
  @uri.clone
59
63
  end
60
64
 
65
+ # Add a few query arguments. For example:
66
+ #
67
+ # Iri.new('https://google.com').add(q: 'test', limit: 10)
68
+ #
69
+ # You can add many of them and they will all be present in the resulting
70
+ # URI, even if their names are the same. In order to make sure you have
71
+ # only one instance of a query argument, use +del+ first:
72
+ #
73
+ # Iri.new('https://google.com').del(:q).add(q: 'test')
74
+ #
61
75
  def add(hash)
62
76
  modify_query do |params|
63
77
  hash.each do |k, v|
@@ -67,6 +81,10 @@ class Iri
67
81
  end
68
82
  end
69
83
 
84
+ # Delete a few query arguments. For example:
85
+ #
86
+ # Iri.new('https://google.com?q=test').del(:q)
87
+ #
70
88
  def del(*keys)
71
89
  modify_query do |params|
72
90
  keys.each do |k|
@@ -75,7 +93,10 @@ class Iri
75
93
  end
76
94
  end
77
95
 
78
- # Replace the query argument(s).
96
+ # Replace query argument(s).
97
+ #
98
+ # Iri.new('https://google.com?q=test').over(q: 'hey you!')
99
+ #
79
100
  def over(hash)
80
101
  modify_query do |params|
81
102
  hash.each do |k, v|
@@ -113,6 +134,13 @@ class Iri
113
134
  end
114
135
  end
115
136
 
137
+ # Replace the fragment part of the URI.
138
+ def fragment(val)
139
+ modify do |c|
140
+ c.fragment = val
141
+ end
142
+ end
143
+
116
144
  # Replace the query part of the URI.
117
145
  def query(val)
118
146
  modify do |c|
@@ -120,7 +148,11 @@ class Iri
120
148
  end
121
149
  end
122
150
 
123
- # Remove the entire path+query+fragment part.
151
+ # Remove the entire path+query+fragment part. For example:
152
+ #
153
+ # Iri.new('https://google.com/a/b?q=test').cut('/hello')
154
+ #
155
+ # The result will contain "https://google.com/hello".
124
156
  def cut(path = '/')
125
157
  modify do |c|
126
158
  c.query = nil
data/test/test_iri.rb CHANGED
@@ -43,6 +43,13 @@ class IriTest < Minitest::Test
43
43
  assert_equal('https://localhost:443/?q=books+about+tennis&limit=10', url)
44
44
  end
45
45
 
46
+ def test_starts_with_empty_uri
47
+ assert_equal(
48
+ 'https:',
49
+ Iri.new.scheme('https').to_s
50
+ )
51
+ end
52
+
46
53
  def test_replaces_scheme
47
54
  assert_equal(
48
55
  'https://google.com/',
@@ -64,6 +71,13 @@ class IriTest < Minitest::Test
64
71
  )
65
72
  end
66
73
 
74
+ def test_replaces_fragment
75
+ assert_equal(
76
+ 'http://localhost/a/b#test',
77
+ Iri.new('http://localhost/a/b#before').fragment('test').to_s
78
+ )
79
+ end
80
+
67
81
  def test_sets_path
68
82
  assert_equal(
69
83
  'http://localhost/hey/you?i=8#test',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -80,7 +80,9 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.31.0
83
- description: Simple Immutable Ruby URI Builder
83
+ description: |-
84
+ Class Iri helps you build a URI and then modify its \
85
+ parts via a simple fluent interface.
84
86
  email: yegor256@gmail.com
85
87
  executables: []
86
88
  extensions: []