regexes 0.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dfe1f0e6dac42eaedbbc257f6abc199ec25810aa5b36e85b76838f2af4ba03e2
4
+ data.tar.gz: 274c09a5bd347bef58ad4505ab9c6502b416767fe62482c7b18b9ab2aafda311
5
+ SHA512:
6
+ metadata.gz: 8e37c49f17d8937c2113ac8a07abfaf01253f74129cd3b63c2dfc79c7c106d726574b1573f6c56483ec4a9d9f848090ed237dde6f66be6d09cd369fa66b9f6d3
7
+ data.tar.gz: b186be7a17e345777976c463b76a38f66c2bfd8ee548b41aa261d5e29cb6bc0941d33716e8d41c20e734afa5093f8b525972dc64ce91f47f1f34e36931db165b
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sebastian Scholl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # regexes
2
+
3
+ Early days. For now it wraps a regex and answers a few questions about text.
4
+
5
+ ```ruby
6
+ require "regexes"
7
+
8
+ pattern = Regexes::Pattern.new(/\d+/)
9
+
10
+ pattern.match?("abc123") # => true
11
+ pattern.matches("a1 b22 c333") # => ["1", "22", "333"]
12
+ pattern.count("a1 b22 c333") # => 3
13
+ pattern.highlight("a1 b22 c333") # => "a[1] b[22] c[333]"
14
+ ```
15
+
16
+ You can pass a string instead of a Regexp, e.g. `Regexes::Pattern.new("\\d+")`.
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Regexes
4
+ # Wraps a regex and answers a few simple questions about text.
5
+ #
6
+ # pattern = Regexes::Pattern.new(/\d+/)
7
+ # pattern.count("a1 b22 c333") # => 3
8
+ # pattern.highlight("a1 b22 c333") # => "a[1] b[22] c[333]"
9
+ class Pattern
10
+ attr_reader :regex
11
+
12
+ def initialize(regex)
13
+ @regex = regex.is_a?(Regexp) ? regex : Regexp.new(regex.to_s)
14
+ end
15
+
16
+ def match?(text)
17
+ regex.match?(text)
18
+ end
19
+
20
+ def matches(text)
21
+ text.to_enum(:scan, regex).map { Regexp.last_match[0] }
22
+ end
23
+
24
+ def count(text)
25
+ matches(text).size
26
+ end
27
+
28
+ def highlight(text, open: "[", close: "]")
29
+ text.gsub(regex) { |match| "#{open}#{match}#{close}" }
30
+ end
31
+
32
+ def to_s
33
+ regex.inspect
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Regexes
4
+ VERSION = "0.0.0"
5
+ end
data/lib/regexes.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "regexes/version"
4
+ require_relative "regexes/pattern"
5
+
6
+ module Regexes
7
+ end
metadata ADDED
@@ -0,0 +1,42 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: regexes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Scholl
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ executables: []
13
+ extensions: []
14
+ extra_rdoc_files: []
15
+ files:
16
+ - LICENSE.txt
17
+ - README.md
18
+ - lib/regexes.rb
19
+ - lib/regexes/pattern.rb
20
+ - lib/regexes/version.rb
21
+ licenses:
22
+ - MIT
23
+ metadata:
24
+ rubygems_mfa_required: 'true'
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.6.9
40
+ specification_version: 4
41
+ summary: Regexes (work in progress).
42
+ test_files: []