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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7f4c3905e79eaad75e82c76fb1ca193d3badfbff09e43b5d768dc548742d138
4
- data.tar.gz: 553127a23ec1cd59622a353ce7f7dbc4d736a8610443f6db2eae8fa8d8020c20
3
+ metadata.gz: 9d6829e3ff7f4532a14b33e05a2365ed2798b8e2c39cfa86262a036052b328e5
4
+ data.tar.gz: 283e2988de9880fe65cef36f29098049991b476e6f9b285e392cdc14745a875d
5
5
  SHA512:
6
- metadata.gz: f3d51171a76be54b832fc6686d332ed832afe57a65b58ebde73a9718064df32f625e3cab6d24521771cc9b983a6f7f98596766a566d297e8456581972853a2df
7
- data.tar.gz: 2ea3b375e191f959236163aac1a83e0778537a442a4628c3c59e920ef13f39fa047610b5c296d0c5c0680129f90419d034f4a5f27758205904187d24258eb378
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://], # 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
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.0
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. `[]` removes nothing:
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
  # ```
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url_extract
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey