uts58 0.2.5 → 0.2.6
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 +4 -4
- data/README.md +4 -0
- data/lib/uts58/extractor.rb +8 -2
- data/lib/uts58/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 337c308523db3149f29705c2430457e99678eab43247a1bd09ac58b62dbaae35
|
|
4
|
+
data.tar.gz: a9c22dbc02f06985e701eaf294b51bb70a33cb818e82405d91a08bccb89f303f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a08a95051e7aca78c7ead8f6a47e0d2dd77c461d656b3392d073ae0bc0597b49bd557b2656324faa49bbd5af97e383af9161180cddca7fbb0b3886d35fa29133
|
|
7
|
+
data.tar.gz: 3915f09fb72db8c630132b4bb3986dbc167e2d6796ff2e4e9a6d5ae7e7b44ea27e6f5cd52c9f676b7dd150ae88cc0fa5441da87ce53136d7af7f00bc807e5973
|
data/README.md
CHANGED
|
@@ -43,6 +43,10 @@ Uts58.extract_urls_with_indices("blogspot.com is still a thing")
|
|
|
43
43
|
# => [{ url: "https://blogspot.com", indices: [0, 12] }]
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
As in twitter-text, you can pass `extract_url_without_protocol: false` to
|
|
47
|
+
find only links that start with `http://` or `https://`. The default is
|
|
48
|
+
`true`, matching UTS58.
|
|
49
|
+
|
|
46
50
|
IDNs are decoded to use UTF8 in the output, for better readability:
|
|
47
51
|
|
|
48
52
|
```ruby
|
data/lib/uts58/extractor.rb
CHANGED
|
@@ -60,9 +60,14 @@ module Uts58
|
|
|
60
60
|
# very common example is input that like "foo example.com bar",
|
|
61
61
|
# where the URL will be https://example.com, including "https://".
|
|
62
62
|
#
|
|
63
|
-
# Returns an empty array if +text+ contains no links.
|
|
64
|
-
#
|
|
63
|
+
# Returns an empty array if +text+ contains no links.
|
|
64
|
+
#
|
|
65
|
+
# +options+ follows twitter-text: pass
|
|
66
|
+
# <tt>extract_url_without_protocol: false</tt> to find only links
|
|
67
|
+
# that start with +http://+ or +https://+. UTS58 doesn't require a
|
|
68
|
+
# scheme, so the default is +true+.
|
|
65
69
|
def extract_urls_with_indices(text, options = {})
|
|
70
|
+
without_protocol = options.fetch(:extract_url_without_protocol, true)
|
|
66
71
|
result = []
|
|
67
72
|
# The '@' in the negative lookbehind is non-obvious part: UTS58
|
|
68
73
|
# has no userinfo, so a host that immediately follows an '@'
|
|
@@ -83,6 +88,7 @@ module Uts58
|
|
|
83
88
|
proto = scheme_match[2]
|
|
84
89
|
s = scheme_match.post_match
|
|
85
90
|
else
|
|
91
|
+
next unless without_protocol
|
|
86
92
|
scheme_offset = 0
|
|
87
93
|
proto = "https://"
|
|
88
94
|
end
|
data/lib/uts58/version.rb
CHANGED