url_extract 0.1.0 → 0.1.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 +4 -4
- data/README.md +10 -6
- data/VERSION +1 -1
- data/lib/url_extract/validations/failure.rb +1 -1
- data/lib/url_extract/validations/options.rb +1 -1
- data/lib/url_extract.rb +5 -3
- 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: 9d6829e3ff7f4532a14b33e05a2365ed2798b8e2c39cfa86262a036052b328e5
|
|
4
|
+
data.tar.gz: 283e2988de9880fe65cef36f29098049991b476e6f9b285e392cdc14745a875d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba7c1f6be9ceb8f4a31ea0bbddbcc09858adfd8f60cda72b762727dda4d4035d7815f7a38bc08d3987d6d1aebc66d96d5a50105fd26c6f5c3d18027dfdaf4fca
|
|
7
|
+
data.tar.gz: ee6408e05c550598c3b91b5901390eab4fa52635d03964564644f16188f0fbce055769035425f1a5cf502cb64d79ccc6eaf6e0cc22bae370ef7fc5a11dc9fed8
|
data/README.md
CHANGED
|
@@ -54,12 +54,12 @@ The defaults are a great start: try them first, and change an option only when a
|
|
|
54
54
|
|
|
55
55
|
```ruby
|
|
56
56
|
default_options = {
|
|
57
|
-
prefixes: %w[https:// http://],
|
|
58
|
-
max_bytesize: 8000,
|
|
59
|
-
trim: %w[? ! . , : ; * _ ~],
|
|
60
|
-
trim_html_entities: true,
|
|
61
|
-
trim_brackets: true,
|
|
62
|
-
on_encoding_error: :warn
|
|
57
|
+
prefixes: %w[https:// http://], # what starts a URL
|
|
58
|
+
max_bytesize: 8000, # the largest URL, in bytes
|
|
59
|
+
trim: %w[? ! . , : ; * _ ~ ' ’ ” » ›], # the strings to remove from the end of a URL
|
|
60
|
+
trim_html_entities: true, # remove an HTML entity from the end of a URL
|
|
61
|
+
trim_brackets: true, # remove a bracket with no partner from the end of a URL
|
|
62
|
+
on_encoding_error: :warn # a text not readable as UTF-8 gives no match, and a warning
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
UrlExtract.scan(text)
|
|
@@ -142,6 +142,10 @@ UrlExtract.scan("Is it https://example.com/x?!").map(&:url)
|
|
|
142
142
|
UrlExtract.scan("(See https://en.wikipedia.org/wiki/Ruby_(programming_language))").map(&:url)
|
|
143
143
|
# => ["https://en.wikipedia.org/wiki/Ruby_(programming_language)"]
|
|
144
144
|
|
|
145
|
+
# Quotes around a URL, and the URL's own quote
|
|
146
|
+
UrlExtract.scan("See 'https://example.com/x' and «https://en.wikipedia.org/wiki/Hawai'i»").map(&:url)
|
|
147
|
+
# => ["https://example.com/x", "https://en.wikipedia.org/wiki/Hawai'i"]
|
|
148
|
+
|
|
145
149
|
# An HTML entity around a URL
|
|
146
150
|
UrlExtract.scan(""https://example.com/x"").map(&:url)
|
|
147
151
|
# => ["https://example.com/x"]
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.1
|
|
@@ -6,7 +6,7 @@ class UrlExtract
|
|
|
6
6
|
# and a short hint of what to provide.
|
|
7
7
|
#
|
|
8
8
|
# Invalid value for trim: "." provided
|
|
9
|
-
# [hint] Provide array of strings like ["?", "!", ".", ",", ":", ";", "*", "_", "~"]
|
|
9
|
+
# [hint] Provide array of strings like ["?", "!", ".", ",", ":", ";", "*", "_", "~", "'", "’", "”", "»", "›"]
|
|
10
10
|
class Failure # :nodoc: all
|
|
11
11
|
# The longest part of a wrong value that an error shows. The value can be a long text, given by mistake.
|
|
12
12
|
MAX_SHOWN_SIZE = 60
|
|
@@ -7,7 +7,7 @@ class UrlExtract
|
|
|
7
7
|
#
|
|
8
8
|
# UrlExtract.scan(text, trim: ".")
|
|
9
9
|
# # ArgumentError: Invalid value for trim: "." provided
|
|
10
|
-
# # [hint] Provide array of strings like ["?", "!", ".", ",", ":", ";", "*", "_", "~"]
|
|
10
|
+
# # [hint] Provide array of strings like ["?", "!", ".", ",", ":", ";", "*", "_", "~", "'", "’", "”", "»", "›"]
|
|
11
11
|
class Options # :nodoc: all
|
|
12
12
|
ON_ENCODING_ERROR = %i[warn skip raise].freeze
|
|
13
13
|
# The private method that checks each option: `check_` and the name of the option.
|
data/lib/url_extract.rb
CHANGED
|
@@ -37,9 +37,9 @@ class UrlExtract
|
|
|
37
37
|
# RFC 9110 recommends that HTTP software supports a URL of at least 8000 bytes:
|
|
38
38
|
# https://www.rfc-editor.org/rfc/rfc9110#section-4.1
|
|
39
39
|
max_bytesize: 8000,
|
|
40
|
-
# The list of the "Autolinks (extension)" part of the GitHub Flavored Markdown Spec, with
|
|
40
|
+
# The list of the "Autolinks (extension)" part of the GitHub Flavored Markdown Spec, with `;` and the closing quotes:
|
|
41
41
|
# https://github.github.com/gfm/#autolinks-extension-
|
|
42
|
-
trim: %w[? ! . , : ; * _ ~].freeze,
|
|
42
|
+
trim: %w[? ! . , : ; * _ ~ ' ’ ” » ›].freeze,
|
|
43
43
|
trim_html_entities: true,
|
|
44
44
|
trim_brackets: true,
|
|
45
45
|
on_encoding_error: :warn
|
|
@@ -87,9 +87,11 @@ class UrlExtract
|
|
|
87
87
|
# UrlExtract.scan(text, max_bytesize: nil).map(&:url) # => ["https://example.com/x", "https://example.com/very/long/path"]
|
|
88
88
|
# ```
|
|
89
89
|
#
|
|
90
|
-
# With `trim:`, the strings to remove from the end of a URL.
|
|
90
|
+
# With `trim:`, the strings to remove from the end of a URL. The default list holds punctuation and closing
|
|
91
|
+
# quotes, and `[]` removes nothing:
|
|
91
92
|
#
|
|
92
93
|
# ```ruby
|
|
94
|
+
# UrlExtract.scan("See 'https://example.com/x'").map(&:url) # => ["https://example.com/x"]
|
|
93
95
|
# UrlExtract.scan("See https://example.com/x.", trim: []).map(&:url) # => ["https://example.com/x."]
|
|
94
96
|
# UrlExtract.scan("See https://example.com/x...»", trim: ["...", "»"]).map(&:url) # => ["https://example.com/x"]
|
|
95
97
|
# ```
|