simple-url 0.0.1
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 +7 -0
- data/lib/key_value_query_string.rb +36 -0
- data/lib/url.rb +20 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e632fad57dab8f0b92dbbd3e2dd107f4ae8be747904b5c64e7ec2c82c1512b10
|
4
|
+
data.tar.gz: '09a1efd13633ef472a58ee35e8de6abc6073fe23bcb751a63d4ee697cfb103cc'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14bc721c66c2703a210e10c3385de9cc7249006140fe248604f8ba904299da1d9dee1b07a83eca58ebc6e073047a3ecec3e8c269603f09755a3e03d911c8b02e
|
7
|
+
data.tar.gz: cb9f169ae237932ffae04f3e8f9ee83e40fb8c57a1574b628e2d02bf70259ceea2b6acfe925a25ec4275d1a47ffd01a075d51cd51956fbc97296bb8c35c708c4
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleUrl
|
4
|
+
class KeyValueQueryString
|
5
|
+
def self.from_string(query_string)
|
6
|
+
ary = URI.decode_www_form(query_string || '')
|
7
|
+
new(ary)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(query)
|
11
|
+
@query = query || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(key, value)
|
15
|
+
@query << [key, value]
|
16
|
+
end
|
17
|
+
|
18
|
+
def [](key)
|
19
|
+
@query.each_with_object([]) do |pair, acc|
|
20
|
+
k, v = pair
|
21
|
+
acc << v if k == key
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def remove(key)
|
26
|
+
@query = @query.reject do |pair|
|
27
|
+
k, = pair
|
28
|
+
k == key
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
URI.encode_www_form(@query)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/url.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleUrl
|
4
|
+
class Url
|
5
|
+
attr_accessor :url, :query
|
6
|
+
attr_reader :query_string_class
|
7
|
+
|
8
|
+
def initialize(url, query_string_class)
|
9
|
+
@url = URI(url)
|
10
|
+
@query_string_class = query_string_class
|
11
|
+
@query = query_string_class.from_string(@url.query)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
q = @query.to_s
|
16
|
+
@url.query = q unless q.empty?
|
17
|
+
@url.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-url
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Dias
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A nice way to work with URLs.
|
14
|
+
email: dias.h.bruno@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/key_value_query_string.rb
|
20
|
+
- lib/url.rb
|
21
|
+
homepage: https://rubygems.org/gems/simple-url
|
22
|
+
licenses:
|
23
|
+
- Unlicense
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.2.26
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A nice way to work with URLs.
|
44
|
+
test_files: []
|