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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29a080a46f1b16f0a6915c30697abb9e91822afa8331572a2652ab5c6f0f5996
4
- data.tar.gz: 82f302762d3aa0d15198078370145081bb027d646f3638b70a0703b1bdfbaa29
3
+ metadata.gz: 337c308523db3149f29705c2430457e99678eab43247a1bd09ac58b62dbaae35
4
+ data.tar.gz: a9c22dbc02f06985e701eaf294b51bb70a33cb818e82405d91a08bccb89f303f
5
5
  SHA512:
6
- metadata.gz: 579b151954c46e0bbb425a0939c6a9210e2fa1186f8748e38bae94d8a98a60a67c897fa4a50b0348d2ac6b1fb9a5213ad3babf7fbe818b12d22519a6a6b6606b
7
- data.tar.gz: bf69e940d10a4d2bf93b76d763342022a92f543622f4c5bbdf48748e3c6a38ecdb56f473e036d979cc974af15f7fb70a452aac5a607a4d004fbe584d8d717faf
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
@@ -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. +options+ is
64
- # accepted for twitter-text compatibility and currently ignored.
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uts58
4
- VERSION = "0.2.5"
4
+ VERSION = "0.2.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uts58
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnt Gulbrandsen