xqsr3 0.8.6 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 033e7dfed425a1390d4fc09533d76e262e26b558
4
- data.tar.gz: 2c08df8949635e57488dca7def484e4ad18ef100
3
+ metadata.gz: 9fc131e56227103bb95b7ccf5dfc3c19dd15b2a6
4
+ data.tar.gz: 4fb63d6d6d8f764e2ca09fc0fe0859897c16a807
5
5
  SHA512:
6
- metadata.gz: 740820caf1bbe4c17bbc2c092e8bec3a6efbf88f0c2593a3dca47213a207802c235ab10c5fc27b4fcb4069b6881b8557f1c875d328d709186e140bfb3fc10d80
7
- data.tar.gz: 0cfef03cd14cdebbb93b52243c28f9f3af187e7e55271fef0764bc5d2a38550ca13f15032fc3eb6d542f7a329ce7fb696161b411a98cd299f205a0ea7557cbc1
6
+ metadata.gz: ec36713f0a9cd50f16d826d3a6ca58a4c36d14ad5aeea9ab0c73a77fb2b90ad7c632dbafd7b9a4dfb4225e1e73c1d1f18bb7020b5b9e12cbc531f10d274ac270
7
+ data.tar.gz: e9c1695f3091a1bd265da1b8943e9a97d9de645c4efddae0798b1d9103508d212348e226330c1f9578f55f0e458390c09765a9243f4505d3028e92563f88691c
@@ -5,7 +5,7 @@
5
5
  # Purpose: multimap container
6
6
  #
7
7
  # Created: 21st March 2007
8
- # Updated: 10th June 2016
8
+ # Updated: 2nd October 2016
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -202,6 +202,16 @@ class MultiMap < ::Hash
202
202
  @inner.each_key { |key| yield key }
203
203
  end
204
204
 
205
+ def each_unflattened
206
+
207
+ @inner.each { |key, value| yield key, value }
208
+ end
209
+
210
+ def each_unflattened_with_index
211
+
212
+ @inner.each_with_index { |kv, index| yield kv, index }
213
+ end
214
+
205
215
  def each_value
206
216
 
207
217
  @inner.each do |key, values|
@@ -5,13 +5,13 @@
5
5
  # Purpose: Definition of the ParameterChecking module
6
6
  #
7
7
  # Created: 12th February 2015
8
- # Updated: 10th June 2016
8
+ # Updated: 26th February 2017
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2015-2016, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2015-2017, Matthew Wilson and Synesis Software
15
15
  # All rights reserved.
16
16
  #
17
17
  # Redistribution and use in source and binary forms, with or without
@@ -54,6 +54,23 @@ module Quality
54
54
  #
55
55
  module ParameterChecking
56
56
 
57
+ private
58
+ module Util_
59
+
60
+ def self.join_with_or a
61
+
62
+ case a.size
63
+ when 1
64
+ a[0]
65
+ when 2
66
+ "#{a[0]} or #{a[1]}"
67
+ else
68
+ "#{a[0...-1].join(', ')}, or #{a[-1]}"
69
+ end
70
+ end
71
+ end # module Util_
72
+
73
+ public
57
74
  # Check a given parameter (value=+value+, name=+name+) for type and value
58
75
  #
59
76
  # @param +value+ the parameter whose value and type is to be checked
@@ -63,7 +80,9 @@ module ParameterChecking
63
80
  # @option +:allow_nil+ the +value+ must not be +nil+ unless this option
64
81
  # is true
65
82
  # @option +:types+ an array of types one of which +value+ must be (or
66
- # must be derived from)
83
+ # must be derived from). One of these types may be an array
84
+ # of types, in which case +value+ may be an array that must
85
+ # consist wholly of those types
67
86
  # @option +:values+ an array of values one of which +value+ must be
68
87
  # @option +:reject_empty+ requires value to respond to +empty?+
69
88
  # message and to do so with false, unless +nil+
@@ -121,9 +140,22 @@ module ParameterChecking
121
140
  type_found = false
122
141
 
123
142
  warn "#{self}::check_parameter: options[:types] of type #{types.class} - should be #{::Array}" unless types.is_a?(Array)
124
- warn "#{self}::check_parameter: options[:types] should contain only classes" if types.is_a?(Array) && !types.all? { |c| ::Class === c }
143
+ warn "#{self}::check_parameter: options[:types] should contain only classes or arrays of classes" if types.is_a?(::Array) && !types.all? { |c| ::Class === c || (::Array === c || c.all? { |c2| ::Class === c2 }) }
144
+
145
+ unless types.any? do |t|
125
146
 
126
- unless types.any? { |t| value.is_a?(t) }
147
+ case t
148
+ when ::Class
149
+
150
+ # the (presumed) scalar argument is of type t?
151
+ value.is_a?(t)
152
+ when ::Array
153
+
154
+ # the (presumed) vector argument's elements are the
155
+ # possible types
156
+ value.all? { |v| t.any? { |t2| v.is_a?(t2) }}
157
+ end
158
+ end
127
159
 
128
160
  failed_check = true
129
161
 
@@ -132,20 +164,29 @@ module ParameterChecking
132
164
  unless message
133
165
 
134
166
  s_name = name.is_a?(String) ? "'#{name}' " : ''
167
+ s_be = 'be' #::Array === value ? 'contain' : 'be'
168
+
169
+ types_0 = types.select { |t| ::Class === t }.uniq
170
+ types_ar = types.select { |t| ::Array === t }.flatten.uniq
171
+
172
+ if types_ar.empty?
135
173
 
136
- case types.size
137
- when 1
174
+ s_types_0 = Util_.join_with_or types_0
138
175
 
139
- s_types = "#{types[0]}"
140
- when 2
176
+ message = "#{param_s} #{s_name}(#{value.class}) must be an instance of #{s_types_0}"
177
+ elsif types_0.empty?
141
178
 
142
- s_types = "#{types[0]} or #{types[1]}"
179
+ s_types_ar = Util_.join_with_or types_ar
180
+
181
+ message = "#{param_s} #{s_name}(#{value.class}) must be an array containing instance(s) of #{s_types_ar}"
143
182
  else
144
183
 
145
- s_types = "#{types[0...-1].join(', ')}, or #{types[-1]}"
146
- end
184
+ s_types_0 = Util_.join_with_or types_0
147
185
 
148
- message = "#{param_s} #{s_name}(#{value.class}) must be an instance of #{s_types}"
186
+ s_types_ar = Util_.join_with_or types_ar
187
+
188
+ message = "#{param_s} #{s_name}(#{value.class}) must be an instance of #{s_types_0}, or an array containing instance(s) of #{s_types_ar}"
189
+ end
149
190
  end
150
191
 
151
192
  raise TypeError, message
data/lib/xqsr3/version.rb CHANGED
@@ -5,13 +5,13 @@
5
5
  # Purpose: Version for Xqsr3 library
6
6
  #
7
7
  # Created: 3rd April 2016
8
- # Updated: 19th May 2016
8
+ # Updated: 26th February 2017
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2016, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2016-2017, Matthew Wilson and Synesis Software
15
15
  # All rights reserved.
16
16
  #
17
17
  # Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@
50
50
  module Xqsr3
51
51
 
52
52
  # Current version of the Xqsr3 library
53
- VERSION = '0.8.6'
53
+ VERSION = '0.10.1'
54
54
 
55
55
  private
56
56
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
  #
3
3
  # executes all other tests
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
4
 
@@ -59,6 +59,36 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
59
59
  assert_raise(::ArgumentError) { MultiMap[ [ :abc ], [] ] }
60
60
  end
61
61
 
62
+ def test_class_operator_subscript_6
63
+
64
+ ar = [ [ :abc, '1' ] ]
65
+
66
+ mm = MultiMap[ar]
67
+
68
+ assert_equal 1, ar.size
69
+ assert_equal 1, mm.size
70
+ assert_equal [ '1' ], mm[:abc]
71
+
72
+ ar = [ [ :abc, '1' ], [ :def, '2' ] ]
73
+
74
+ mm = MultiMap[ar]
75
+
76
+ assert_equal 2, ar.size
77
+ assert_equal 2, mm.size
78
+ assert_equal [ '1' ], mm[:abc]
79
+ assert_equal [ '2' ], mm[:def]
80
+
81
+ ar = [ [ 1, 11 ], [ 1, 111 ], [ 2, 22 ], [ 3, 333 ], [ 1, 1111 ] ]
82
+
83
+ mm = MultiMap[ar]
84
+
85
+ assert_equal 5, ar.size
86
+ assert_equal 3, mm.size
87
+ assert_equal [ 11, 111, 1111 ], mm[1]
88
+ assert_equal [ 22 ], mm[2]
89
+ assert_equal [ 333 ], mm[3]
90
+ end
91
+
62
92
  def test_instance_operator_equals
63
93
 
64
94
  mm1 = MultiMap.new
@@ -323,6 +353,52 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
323
353
  assert_equal [ [ :abc, 'a1', 0 ], [ :abc, 'a2', 1 ], [ :abc, 'a3', 2 ], [ :abc, 'a4', 3 ], [ :ghi, 'g1', 4 ], [ :ghi, 'g2', 5 ] ], r
324
354
  end
325
355
 
356
+ def test_each_unflattened
357
+
358
+ mm = MultiMap.new
359
+
360
+ mm.push :def
361
+ mm.push :abc, 'a1', 'a2', 'a3', 'a4'
362
+ mm.push :ghi, 'g1', 'g2'
363
+
364
+ r = []
365
+
366
+ mm.each_unflattened do |key, value|
367
+
368
+ r << [ key, value ]
369
+ end
370
+
371
+ r.sort!
372
+
373
+ assert_equal 3, r.size
374
+ assert_equal [ :abc, [ 'a1', 'a2', 'a3', 'a4' ] ], r[0]
375
+ assert_equal [ :def, [] ], r[1]
376
+ assert_equal [ :ghi, [ 'g1', 'g2' ] ], r[2]
377
+ end
378
+
379
+ def test_each_unflattened_with_index
380
+
381
+ mm = MultiMap.new
382
+
383
+ mm.push :def
384
+ mm.push :abc, 'a1', 'a2', 'a3', 'a4'
385
+ mm.push :ghi, 'g1', 'g2'
386
+
387
+ r = []
388
+
389
+ mm.each_unflattened_with_index do |(key, value), index|
390
+
391
+ r << [ key, value, index ]
392
+ end
393
+
394
+ r.sort!
395
+
396
+ assert_equal 3, r.size
397
+ assert_equal [ :abc, [ 'a1', 'a2', 'a3', 'a4' ], 1 ], r[0]
398
+ assert_equal [ :def, [], 0 ], r[1]
399
+ assert_equal [ :ghi, [ 'g1', 'g2' ], 2 ], r[2]
400
+ end
401
+
326
402
  def test_empty
327
403
 
328
404
  mm = MultiMap.new
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
  #
3
3
  # executes all other tests
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
  #
3
3
  # executes all other tests
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
  #
3
3
  # executes all other tests
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
  #
3
3
  # executes all other tests
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), '../../../..', 'lib')
4
4
 
@@ -159,7 +159,7 @@ end
159
159
  assert_match /^parameter 'a' \(String\) must be an instance of Hash$/, ax.message
160
160
  rescue => x
161
161
 
162
- assert(false, "wrong exception type (#{x.class})")
162
+ assert(false, "wrong exception type #{x.class} (with message '#{x.message}')")
163
163
  end
164
164
 
165
165
 
@@ -172,10 +172,56 @@ end
172
172
  assert_match /^parameter 'a' value '' not found equal\/within any of required values or ranges$/, ax.message
173
173
  rescue => x
174
174
 
175
- assert(false, "wrong exception type (#{x.class})")
175
+ assert(false, "wrong exception type #{x.class} (with message '#{x.message}')")
176
176
  end
177
+ end
178
+
179
+
180
+ # test 7 - verify that can include an array of types in the array of types
181
+
182
+ def check_method_7 a, types, values, options = {}, &block
177
183
 
184
+ self.class.check_param a, 'a', options.merge({ types: types, values: values }), &block
178
185
  end
179
186
 
187
+ def test_7
188
+
189
+ assert_equal [], check_method_7([], [ ::Array ], nil)
190
+
191
+ assert_equal [ 'abc' ], check_method_7([ 'abc' ], [ ::Array ], nil)
192
+
193
+ assert_equal [ 'abc' ], check_method_7([ 'abc' ], [ [ ::String ] ], nil)
194
+
195
+ assert_equal [ 'abc' ], check_method_7([ 'abc' ], [ [ ::Regexp, ::String ] ], nil)
196
+
197
+ assert_equal [ :'abc' ], check_method_7([ :'abc' ], [ [ ::Regexp, ::Symbol ] ], nil)
198
+
199
+
200
+ begin
201
+ check_method_7 [ 'abc' ], [ ::Symbol, [ ::Regexp, ::Symbol ], ::Hash ], nil
202
+
203
+ assert(false, 'should not get here')
204
+ rescue TypeError => ax
205
+
206
+ assert_match /^parameter 'a' \(Array\) must be an instance of Symbol or Hash, or an array containing instance\(s\) of Regexp or Symbol$/, ax.message
207
+ rescue => x
208
+
209
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
210
+ end
211
+
212
+
213
+ begin
214
+ check_method_7 [ 'abc' ], [ [ ::Regexp, ::Symbol ] ], nil
215
+
216
+ assert(false, 'should not get here')
217
+ rescue TypeError => ax
218
+
219
+ assert_match /^parameter 'a' \(Array\) must be an array containing instance\(s\) of Regexp or Symbol$/, ax.message
220
+ rescue => x
221
+
222
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
223
+ end
224
+
225
+ end
180
226
  end
181
227
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
  #
3
3
  # executes all other tests
4
4
 
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), '../../lib')
4
4
 
@@ -34,4 +34,3 @@ class Test_version < Test::Unit::TestCase
34
34
  end
35
35
  end
36
36
 
37
-
data/test/unit/ts_all.rb CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby
1
+ #! /usr/bin/env ruby
2
2
  #
3
3
  # executes all other tests
4
4
 
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.8.6
4
+ version: 0.10.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: 2016-06-19 00:00:00.000000000 Z
11
+ date: 2017-02-26 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,32 +19,30 @@ 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/diagnostics/exception_utilities.rb
28
26
  - lib/xqsr3/doc_.rb
29
- - lib/xqsr3/extensions/enumerable.rb
30
27
  - lib/xqsr3/extensions/enumerable/collect_with_index.rb
31
28
  - lib/xqsr3/extensions/enumerable/unique.rb
32
- - lib/xqsr3/extensions/io.rb
29
+ - lib/xqsr3/extensions/enumerable.rb
33
30
  - lib/xqsr3/extensions/io/writelines.rb
34
- - lib/xqsr3/extensions/kernel.rb
31
+ - lib/xqsr3/extensions/io.rb
35
32
  - lib/xqsr3/extensions/kernel/raise_with_options.rb
36
- - lib/xqsr3/extensions/string.rb
33
+ - lib/xqsr3/extensions/kernel.rb
37
34
  - lib/xqsr3/extensions/string/ends_with.rb
38
35
  - lib/xqsr3/extensions/string/map_option_string.rb
39
36
  - lib/xqsr3/extensions/string/starts_with.rb
40
37
  - lib/xqsr3/extensions/string/to_symbol.rb
41
- - lib/xqsr3/extensions/test/unit.rb
38
+ - lib/xqsr3/extensions/string.rb
42
39
  - lib/xqsr3/extensions/test/unit/assert_eql.rb
43
40
  - lib/xqsr3/extensions/test/unit/assert_not.rb
44
41
  - lib/xqsr3/extensions/test/unit/assert_not_eql.rb
42
+ - lib/xqsr3/extensions/test/unit.rb
45
43
  - lib/xqsr3/io/writelines.rb
46
- - lib/xqsr3/quality.rb
47
44
  - lib/xqsr3/quality/parameter_checking.rb
45
+ - lib/xqsr3/quality.rb
48
46
  - lib/xqsr3/string_utilities/ends_with.rb
49
47
  - lib/xqsr3/string_utilities/starts_with.rb
50
48
  - lib/xqsr3/string_utilities/to_symbol.rb
@@ -75,6 +73,8 @@ files:
75
73
  - test/unit/quality/ts_all.rb
76
74
  - test/unit/tc_version.rb
77
75
  - test/unit/ts_all.rb
76
+ - README.md
77
+ - LICENSE
78
78
  homepage: http://github.com/synesissoftware/xqsr3
79
79
  licenses:
80
80
  - 3-clause BSD
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.4.2
98
+ rubygems_version: 2.0.14.1
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: xqsr3