xqsr3 0.13.3 → 0.14.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
  SHA1:
3
- metadata.gz: a62fcdc4c1aa7176aa20acf04a477f9ce9e32dde
4
- data.tar.gz: 9e3085307d16b630cbe34d5e7d243b4f3ec18622
3
+ metadata.gz: 1d2428b61c6d1ffe6859382fac62b8ab460cafb8
4
+ data.tar.gz: c8b15079affd7d14f1fc68fa64aa83b14ccc0c3c
5
5
  SHA512:
6
- metadata.gz: 947e35e638cbd5ce7bdef5811d8c3f9de6923f697aff9212f371fda83b049b4032dd7f789f7183720c53714967c13e5ce62501071dbc11c93bb85a06adea8e41
7
- data.tar.gz: b458cea2b2fb99ceb8a42b5262f6556fa926aecb2c2489212ede046d503d82a60acc1fb735049bf5e4eff8815aee6caab20dc23f71abae962f560bb12b4b4f3c
6
+ metadata.gz: f8e73c19d7d688d02e22a4db0d121d0d1da5b9432d1fe801ee55667f2f90eb8079ff622ae4d924dbb0e71e2d63b2f9d5c149923c979261acfddd768e8c40c711
7
+ data.tar.gz: f208ebf0cabcb05ec49064db7478f0f5b37a0de948207cadec78662e66127593c9e08a25b456b816282a9998738860dc83f3919b88bd5ec542f55bbef8230a80
@@ -0,0 +1,11 @@
1
+
2
+ require 'xqsr3/hash_utilities/key_matching'
3
+
4
+ class Hash
5
+
6
+ def has_match? re, **options
7
+
8
+ return ::Xqsr3::HashUtilities::KeyMatching.has_match? self, re, **options
9
+ end
10
+ end
11
+
@@ -0,0 +1,11 @@
1
+
2
+ require 'xqsr3/hash_utilities/key_matching'
3
+
4
+ class Hash
5
+
6
+ def match re, **options
7
+
8
+ return ::Xqsr3::HashUtilities::KeyMatching.match self, re, **options
9
+ end
10
+ end
11
+
@@ -0,0 +1,5 @@
1
+
2
+ require 'xqsr3/extensions/hash/deep_transform'
3
+ require 'xqsr3/extensions/hash/has_match'
4
+ require 'xqsr3/extensions/hash/match'
5
+
@@ -0,0 +1,175 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/hash_utilities/key_matching.rb
4
+ #
5
+ # Purpose: Definition of the ::Xqsr3::HashUtilities::KeyMatching
6
+ # module
7
+ #
8
+ # Created: 15th November 2017
9
+ # Updated: 15th November 2017
10
+ #
11
+ # Home: http://github.com/synesissoftware/xqsr3
12
+ #
13
+ # Author: Matthew Wilson
14
+ #
15
+ # Copyright (c) 2017, Matthew Wilson and Synesis Software
16
+ # All rights reserved.
17
+ #
18
+ # Redistribution and use in source and binary forms, with or without
19
+ # modification, are permitted provided that the following conditions are
20
+ # met:
21
+ #
22
+ # * Redistributions of source code must retain the above copyright notice,
23
+ # this list of conditions and the following disclaimer.
24
+ #
25
+ # * Redistributions in binary form must reproduce the above copyright
26
+ # notice, this list of conditions and the following disclaimer in the
27
+ # documentation and/or other materials provided with the distribution.
28
+ #
29
+ # * Neither the names of the copyright holder nor the names of its
30
+ # contributors may be used to endorse or promote products derived from
31
+ # this software without specific prior written permission.
32
+ #
33
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
34
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
35
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
37
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
+ #
45
+ # ######################################################################## #
46
+
47
+
48
+ require 'xqsr3/quality/parameter_checking'
49
+
50
+ # ##########################################################
51
+ # ::Xqsr3::HashUtilities::KeyMatching
52
+
53
+ =begin
54
+ =end
55
+
56
+ module Xqsr3
57
+ module HashUtilities
58
+
59
+ module KeyMatching
60
+
61
+ private
62
+ def self.do_match_ h, re, **options
63
+
64
+ ::Xqsr3::Quality::ParameterChecking.check_parameter h, 'h', responds_to: [ :[], :has_key?, :each ]
65
+
66
+ return h[re] if h.has_key? re
67
+
68
+ case re
69
+ when ::Regexp
70
+
71
+ h.each do |k, v|
72
+
73
+ case k
74
+ when ::Regexp
75
+
76
+ next
77
+ else
78
+
79
+ return v if k.to_s =~ re
80
+ end
81
+ end
82
+ else
83
+
84
+ h.each do |k, v|
85
+
86
+ case k
87
+ when ::Regexp
88
+
89
+ return v if re.to_s =~ k
90
+ else
91
+
92
+ next
93
+ end
94
+ end
95
+ end
96
+
97
+ nil
98
+ end
99
+
100
+ def self.do_has_match_ h, re, **options
101
+
102
+ ::Xqsr3::Quality::ParameterChecking.check_parameter h, 'h', responds_to: [ :[], :has_key?, :each ]
103
+
104
+ return true if h.has_key? re
105
+
106
+ case re
107
+ when ::Regexp
108
+
109
+ h.each do |k, v|
110
+
111
+ case k
112
+ when ::Regexp
113
+
114
+ next
115
+ else
116
+
117
+ return true if k.to_s =~ re
118
+ end
119
+ end
120
+ else
121
+
122
+ h.each do |k, v|
123
+
124
+ case k
125
+ when ::Regexp
126
+
127
+ return true if re.to_s =~ k
128
+ else
129
+
130
+ next
131
+ end
132
+ end
133
+ end
134
+
135
+ false
136
+ end
137
+ public
138
+
139
+ # Retrieves the value object corresponding to the first key object that
140
+ # matches the given +re+, in the hash +h+, according to the given
141
+ # options.
142
+ def self.match h, re, **options
143
+
144
+ Xqsr3::HashUtilities::KeyMatching.do_match_ h, re, **options
145
+ end
146
+
147
+ # Returns true if the hash +h+ contains a key object that matches the
148
+ # given +re+, according to the given options
149
+ def self.has_match? h, re, **options
150
+
151
+ Xqsr3::HashUtilities::KeyMatching.do_has_match_ h, re, **options
152
+ end
153
+
154
+ # Retrieves the value object corresponding to the first key object that
155
+ # matches the given +re+, in the hash +h+, according to the given
156
+ # options.
157
+ def match h, re, **options
158
+
159
+ Xqsr3::HashUtilities::KeyMatching.do_match_ h, re, **options
160
+ end
161
+
162
+ # Returns true if the hash +h+ contains a key object that matches the
163
+ # given +re+, according to the given options
164
+ def has_match? h, re, **options
165
+
166
+ Xqsr3::HashUtilities::KeyMatching.do_has_match_ h, re, **options
167
+ end
168
+
169
+ end # module KeyMatching
170
+
171
+ end # module HashUtilities
172
+ end # module Xqsr3
173
+
174
+ # ############################## end of file ############################# #
175
+
@@ -61,8 +61,6 @@ module QuoteIf
61
61
 
62
62
  def self.string_quote_if_array_ s, options
63
63
 
64
- #$stderr.puts "#{self}#{__method__}(s (#{s.class})='#{s}', options (#{options.class})='#{options}'"
65
-
66
64
  s = s.to_s unless String === s
67
65
 
68
66
  quotes = options[:quotes] || [ '"', '"' ]
@@ -70,8 +68,6 @@ module QuoteIf
70
68
 
71
69
  quotables = options[:quotables] || /\s/
72
70
 
73
- #$stderr.puts "quotables (#{quotables.class}): [#{quotables}]"
74
-
75
71
  case quotables
76
72
  when ::String
77
73
 
data/lib/xqsr3/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for Xqsr3 library
6
6
  #
7
7
  # Created: 3rd April 2016
8
- # Updated: 1st November 2017
8
+ # Updated: 15th November 2017
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -50,7 +50,7 @@
50
50
  module Xqsr3
51
51
 
52
52
  # Current version of the Xqsr3 library
53
- VERSION = '0.13.3'
53
+ VERSION = '0.14.1'
54
54
 
55
55
  private
56
56
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -0,0 +1,100 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
+
5
+ require 'xqsr3/hash_utilities/key_matching'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+ require 'test/unit'
9
+
10
+
11
+ class Test_Xqsr3_HashUtilities_has_match_by_module < Test::Unit::TestCase
12
+
13
+ Matching = ::Xqsr3::HashUtilities::KeyMatching
14
+
15
+ def test_against_none_re
16
+
17
+ h = {
18
+
19
+ :abc => :abc,
20
+ 'abc' => 'abc',
21
+ 'def' => 'def',
22
+ :nil => nil,
23
+ :sym => :sym,
24
+ }
25
+
26
+ assert_false Matching.has_match?(h, '')
27
+ assert_true Matching.has_match?(h, 'def')
28
+ assert_false Matching.has_match?(h, 'ghi')
29
+ assert_true Matching.has_match?(h, :nil)
30
+ assert_false Matching.has_match?(h, 'nil')
31
+ assert_true Matching.has_match?(h, :sym)
32
+ assert_false Matching.has_match?(h, 'sym')
33
+ end
34
+
35
+ def test_against_empty_re
36
+
37
+ h = {
38
+
39
+ :abc => :abc,
40
+ 'abc' => 'abc',
41
+ 'def' => 'def',
42
+ :nil => nil,
43
+ :sym => :sym,
44
+ }
45
+
46
+ assert_true Matching.has_match?(h, //)
47
+
48
+ assert_true Matching.has_match?(h, /def/)
49
+ assert_true Matching.has_match?(h, /de/)
50
+ assert_true Matching.has_match?(h, /^de/)
51
+ assert_false Matching.has_match?(h, /de$/)
52
+ end
53
+ end
54
+
55
+
56
+ require 'xqsr3/extensions/hash/has_match'
57
+
58
+ class Test_Xqsr3_HashUtilities_has_match_by_include < Test::Unit::TestCase
59
+
60
+ def test_against_none_re
61
+
62
+ h = {
63
+
64
+ :abc => :abc,
65
+ 'abc' => 'abc',
66
+ 'def' => 'def',
67
+ :nil => nil,
68
+ :sym => :sym,
69
+ }
70
+
71
+ assert_false h.has_match?('')
72
+ assert_true h.has_match?('def')
73
+ assert_false h.has_match?('ghi')
74
+ assert_true h.has_match?(:nil)
75
+ assert_false h.has_match?('nil')
76
+ assert_true h.has_match?(:sym)
77
+ assert_false h.has_match?('sym')
78
+ end
79
+
80
+ def test_against_empty_re
81
+
82
+ h = {
83
+
84
+ :abc => :abc,
85
+ 'abc' => 'abc',
86
+ 'def' => 'def',
87
+ :nil => nil,
88
+ :sym => :sym,
89
+ }
90
+
91
+ assert_true h.has_match?(//)
92
+
93
+ assert_true h.has_match?(/def/)
94
+ assert_true h.has_match?(/de/)
95
+ assert_true h.has_match?(/^de/)
96
+ assert_false h.has_match?(/de$/)
97
+ end
98
+ end
99
+
100
+
@@ -0,0 +1,130 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
+
5
+ require 'xqsr3/hash_utilities/key_matching'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+ require 'test/unit'
9
+
10
+
11
+ class Test_Xqsr3_HashUtilities_match_by_module < Test::Unit::TestCase
12
+
13
+ Matching = ::Xqsr3::HashUtilities::KeyMatching
14
+
15
+ def test_against_none_re
16
+
17
+ h = {
18
+
19
+ :abc => :abc,
20
+ 'abc' => 'abc',
21
+ 'def' => 'def',
22
+ :nil => nil,
23
+ :sym => :sym,
24
+ }
25
+
26
+ assert_nil Matching.match(h, '')
27
+ assert_not_nil Matching.match(h, 'def')
28
+ assert_nil Matching.match(h, 'ghi')
29
+ assert_nil Matching.match(h, :nil) # although this is matching!
30
+ assert_nil Matching.match(h, 'nil')
31
+ assert_not_nil Matching.match(h, :sym)
32
+ assert_nil Matching.match(h, 'sym')
33
+ end
34
+
35
+ def test_against_empty_re
36
+
37
+ h = {
38
+
39
+ :abc => :abc,
40
+ 'abc' => 'abc',
41
+ 'def' => 'def',
42
+ :nil => nil,
43
+ :sym => :sym,
44
+ }
45
+
46
+ assert_not_nil Matching.match(h, //)
47
+ assert_equal h.first[1], Matching.match(h, //)
48
+
49
+ assert_equal 'def', Matching.match(h, /def/)
50
+ assert_equal 'def', Matching.match(h, /de/)
51
+ assert_equal 'def', Matching.match(h, /^de/)
52
+ assert_nil Matching.match(h, /de$/)
53
+ end
54
+
55
+ def test_hash_containing_re
56
+
57
+ h = {
58
+
59
+ /bc/ => :bc,
60
+ /de/ => :de,
61
+ :abc => :abc,
62
+ }
63
+
64
+ assert_nil Matching.match(h, '')
65
+ assert_nil Matching.match(h, :ab)
66
+ assert_equal :bc, Matching.match(h, :abcd)
67
+ end
68
+ end
69
+
70
+
71
+ require 'xqsr3/extensions/hash/match'
72
+
73
+ class Test_Xqsr3_HashUtilities_match_by_include < Test::Unit::TestCase
74
+
75
+ def test_against_none_re
76
+
77
+ h = {
78
+
79
+ :abc => :abc,
80
+ 'abc' => 'abc',
81
+ 'def' => 'def',
82
+ :nil => nil,
83
+ :sym => :sym,
84
+ }
85
+
86
+ assert_nil h.match('')
87
+ assert_not_nil h.match('def')
88
+ assert_nil h.match('ghi')
89
+ assert_nil h.match(:nil) # although this is matching!
90
+ assert_nil h.match('nil')
91
+ assert_not_nil h.match(:sym)
92
+ assert_nil h.match('sym')
93
+ end
94
+
95
+ def test_against_empty_re
96
+
97
+ h = {
98
+
99
+ :abc => :abc,
100
+ 'abc' => 'abc',
101
+ 'def' => 'def',
102
+ :nil => nil,
103
+ :sym => :sym,
104
+ }
105
+
106
+ assert_not_nil h.match(//)
107
+ assert_equal h.first[1], h.match(//)
108
+
109
+ assert_equal 'def', h.match(/def/)
110
+ assert_equal 'def', h.match(/de/)
111
+ assert_equal 'def', h.match(/^de/)
112
+ assert_nil h.match(/de$/)
113
+ end
114
+
115
+ def test_hash_containing_re
116
+
117
+ h = {
118
+
119
+ /bc/ => :bc,
120
+ /de/ => :de,
121
+ :abc => :abc,
122
+ }
123
+
124
+ assert_nil h.match('')
125
+ assert_nil h.match(:ab)
126
+ assert_equal :bc, h.match(:abcd)
127
+ end
128
+ end
129
+
130
+
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
+
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
9
+
10
+ # all ts_*rb in immediate sub-directories
11
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
12
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xqsr3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  eXtensions by fine Quantum for Standard Ruby and 3rd-party libraries is a
@@ -19,39 +19,41 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - LICENSE
23
- - README.md
24
22
  - lib/xqsr3/command_line_utilities/map_option_string.rb
25
23
  - lib/xqsr3/containers/frequency_map.rb
26
24
  - lib/xqsr3/containers/multi_map.rb
27
25
  - lib/xqsr3/conversion/bool_parser.rb
28
26
  - lib/xqsr3/diagnostics/exception_utilities.rb
29
27
  - lib/xqsr3/doc_.rb
30
- - lib/xqsr3/extensions/enumerable.rb
31
28
  - lib/xqsr3/extensions/enumerable/collect_with_index.rb
32
29
  - lib/xqsr3/extensions/enumerable/unique.rb
30
+ - lib/xqsr3/extensions/enumerable.rb
33
31
  - lib/xqsr3/extensions/hash/deep_transform.rb
34
- - lib/xqsr3/extensions/io.rb
32
+ - lib/xqsr3/extensions/hash/has_match.rb
33
+ - lib/xqsr3/extensions/hash/match.rb
34
+ - lib/xqsr3/extensions/hash.rb
35
35
  - lib/xqsr3/extensions/io/writelines.rb
36
- - lib/xqsr3/extensions/kernel.rb
36
+ - lib/xqsr3/extensions/io.rb
37
37
  - lib/xqsr3/extensions/kernel/raise_with_options.rb
38
- - lib/xqsr3/extensions/string.rb
38
+ - lib/xqsr3/extensions/kernel.rb
39
39
  - lib/xqsr3/extensions/string/ends_with.rb
40
40
  - lib/xqsr3/extensions/string/map_option_string.rb
41
41
  - lib/xqsr3/extensions/string/quote_if.rb
42
42
  - lib/xqsr3/extensions/string/starts_with.rb
43
43
  - lib/xqsr3/extensions/string/to_bool.rb
44
44
  - lib/xqsr3/extensions/string/to_symbol.rb
45
- - lib/xqsr3/extensions/test/unit.rb
45
+ - lib/xqsr3/extensions/string.rb
46
46
  - lib/xqsr3/extensions/test/unit/assert_eql.rb
47
47
  - lib/xqsr3/extensions/test/unit/assert_false.rb
48
48
  - lib/xqsr3/extensions/test/unit/assert_not.rb
49
49
  - lib/xqsr3/extensions/test/unit/assert_not_eql.rb
50
50
  - lib/xqsr3/extensions/test/unit/assert_true.rb
51
+ - lib/xqsr3/extensions/test/unit.rb
51
52
  - lib/xqsr3/hash_utilities/deep_transform.rb
53
+ - lib/xqsr3/hash_utilities/key_matching.rb
52
54
  - lib/xqsr3/io/writelines.rb
53
- - lib/xqsr3/quality.rb
54
55
  - lib/xqsr3/quality/parameter_checking.rb
56
+ - lib/xqsr3/quality.rb
55
57
  - lib/xqsr3/string_utilities/ends_with.rb
56
58
  - lib/xqsr3/string_utilities/quote_if.rb
57
59
  - lib/xqsr3/string_utilities/starts_with.rb
@@ -84,6 +86,9 @@ files:
84
86
  - test/unit/extensions/string/tc_to_symbol.rb
85
87
  - test/unit/extensions/string/ts_all.rb
86
88
  - test/unit/extensions/ts_all.rb
89
+ - test/unit/hash_utilities/tc_has_match.rb
90
+ - test/unit/hash_utilities/tc_match.rb
91
+ - test/unit/hash_utilities/ts_all.rb
87
92
  - test/unit/io/tc_writelines.rb
88
93
  - test/unit/io/ts_all.rb
89
94
  - test/unit/quality/tc_parameter_checking.rb
@@ -93,6 +98,8 @@ files:
93
98
  - test/unit/xml/ts_all.rb
94
99
  - test/unit/xml/utilities/tc_compare.rb
95
100
  - test/unit/xml/utilities/ts_all.rb
101
+ - README.md
102
+ - LICENSE
96
103
  homepage: http://github.com/synesissoftware/xqsr3
97
104
  licenses:
98
105
  - 3-clause BSD
@@ -113,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
120
  version: '0'
114
121
  requirements: []
115
122
  rubyforge_project:
116
- rubygems_version: 2.4.2
123
+ rubygems_version: 2.0.14.1
117
124
  signing_key:
118
125
  specification_version: 4
119
126
  summary: xqsr3