ruby_regexp_wrapper 0.1.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: 2a7904a1b291263632fb771e277947910edc8d6c1f84c331edb62d6ada473a6e
4
+ data.tar.gz: 4070a086badc49d0fb9b5b08f70baf8afbb3de4ac374739a44ef4019b3b90ae5
5
+ SHA512:
6
+ metadata.gz: fda5f7eaa24546365f74b98df6d69ec8d23359fd237cfb2f9dabd3be71aaf546569dd35c2142e110887e00ca416ebb2a19f6fb160f78a40b6c2b14f7eafee6e7
7
+ data.tar.gz: 1de91f22c3ab439be44deb9ae8c8be1a28f34b0642d6b1104dc117b47d4a803948f151d09fd5c9bdc0832a9b155d1dcbd7603b59ff718cf89e2a2e62e3e565a8
@@ -0,0 +1,36 @@
1
+ module RegexpWrapper
2
+ class QueryWrapper
3
+ attr_accessor :header, :body, :footer
4
+
5
+ def initialize
6
+ @header = ""
7
+ @body = ""
8
+ @footer = ""
9
+ end
10
+
11
+ def start_with!(content)
12
+ @header = "^#{content}"
13
+ self
14
+ end
15
+
16
+ def end_with!(content)
17
+ @footer = "#{content}\\z"
18
+ self
19
+ end
20
+
21
+ def has!(content)
22
+ @body = @body + ".*#{content}"
23
+ self
24
+ end
25
+
26
+ def to_regexp
27
+ express = @header + @body + ".*" + @footer
28
+ Regexp.new(express)
29
+ end
30
+
31
+ def =~(content)
32
+ content.to_s =~ to_regexp
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+ require_relative 'query_wrapper'
5
+ class QueryWrapperTest < Minitest::Test
6
+ def setup
7
+ @queryWrapper = RegexpWrapper::QueryWrapper.new
8
+ end
9
+
10
+ def test_start_with_and_end_with
11
+ express = @queryWrapper.start_with!("a").end_with!("z").to_regexp
12
+ assert_equal(/^a.*z\z/,express)
13
+ end
14
+
15
+ def test_has
16
+ express = @queryWrapper.start_with!("a").has!("BBB").has!("DDD").end_with!("z").to_regexp
17
+ assert_equal(/^a.*BBB.*DDD.*z\z/,express)
18
+ end
19
+
20
+ def test_match_start_with
21
+ assert("abc" =~ @queryWrapper.start_with!("a").to_regexp)
22
+ end
23
+
24
+ def test_match_end_with
25
+ assert("abc" =~ @queryWrapper.end_with!("c").to_regexp)
26
+ end
27
+
28
+ def test_match_start_with_a_and_end_with_c
29
+ assert(@queryWrapper.start_with!("a").end_with!("c") =~ "abc")
30
+ assert_match(@queryWrapper.start_with!("a").end_with!("c").to_regexp,"abc")
31
+ refute_match(@queryWrapper.start_with!("a").end_with!("c").to_regexp,"abd")
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_regexp_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 秦晨
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 可以简单的通过函数式拼接正则表达式
14
+ email:
15
+ - qsc1956826@Gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/regexp_wrapper/query_wrapper.rb
21
+ - lib/regexp_wrapper/query_wrapper_test.rb
22
+ homepage: https://github.com/GengCen-Qin/ruby_regexp_wrapper
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.4.10
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: 对正则表达式进行封装函数
45
+ test_files: []