xqsr3 0.37.2 → 0.38.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: f10bad46d3e4578fbf386537a6bf5e72e4b690d7
4
- data.tar.gz: 71706b979d66b50232e82fe32259e4c69c1dd697
3
+ metadata.gz: 893916b4985f2cf4aacd3880f28d9199b3137f49
4
+ data.tar.gz: d611a888f54fc3d6bee966a040530637bdfe2423
5
5
  SHA512:
6
- metadata.gz: c1cf52793a168a5be1102777e347b657fc12dab1549321fd028e66fa2c64523651b66c8c9669d17079b4824309a0217063c6876b82f0d44c1b909973478e88e1
7
- data.tar.gz: 076ce8d398e4b0f67012bf6465b9a1ba005ef4d6fe60bc60736b42ea9269448535df9677da2702ac1b9c868f6f2bd3560dd92f2815d7c4cfc7fb20438f0a3528
6
+ metadata.gz: 222348a3e0621835acbb5df342e2625eb6f6c7d355b59e9aded4e105e3acdbfe27a13cff0af939964ecde0eab65f16a5bebd8560afb71781a653c98ba981cc0b
7
+ data.tar.gz: efd82ceb69653fcc88954b3fb03267d3719e00642de1c7a2de564fe008751e0476be9625da6037af8bdcc1aecbf242ceced924f29403858a9d5a3b8eff861391
data/README.md CHANGED
@@ -23,7 +23,7 @@ It may be pronounced (lamely) as "excusers".
23
23
  Install via **gem** as in:
24
24
 
25
25
  ```
26
- gem install libclimate-ruby
26
+ gem install libclimate-ruby
27
27
  ```
28
28
 
29
29
  or add it to your `Gemfile`.
@@ -6,12 +6,13 @@
6
6
  # ::Xqsr3::CommandLineUtilities::MapOptionString module
7
7
  #
8
8
  # Created: 15th April 2016
9
- # Updated: 15th April 2019
9
+ # Updated: 19th July 2022
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
13
13
  # Author: Matthew Wilson
14
14
  #
15
+ # Copyright (c) 2019-2022, Matthew Wilson and Synesis Information Systems
15
16
  # Copyright (c) 2016-2019, Matthew Wilson and Synesis Software
16
17
  # All rights reserved.
17
18
  #
@@ -285,9 +285,13 @@ class FrequencyMap
285
285
  # keys must be created and sorted from which enumeration is directed
286
286
  def each_by_key
287
287
 
288
- @elements.keys.sort.each do |key|
288
+ sorted_elements = @elements.sort { |a, b| a[0] <=> b[0] }
289
289
 
290
- yield key, @elements[key]
290
+ return sorted_elements.each unless block_given?
291
+
292
+ sorted_elements.each do |k, v|
293
+
294
+ yield k, v
291
295
  end
292
296
  end
293
297
 
@@ -298,22 +302,13 @@ class FrequencyMap
298
302
  # and map all entries into it in order to achieve the ordering
299
303
  def each_by_frequency
300
304
 
301
- tm = {}
302
- @elements.each do |element, frequency|
303
-
304
- tm[frequency] = [] unless tm.has_key?(frequency)
305
+ ar = @elements.to_a.sort { |a, b| b[1] <=> a[1] }
305
306
 
306
- tm[frequency].push element
307
- end
308
-
309
- keys = tm.keys.sort.reverse
310
- keys.each do |frequency|
307
+ return ar.each unless block_given?
311
308
 
312
- elements = tm[frequency].sort
313
- elements.each do |element|
309
+ ar.each do |k, v|
314
310
 
315
- yield element, frequency
316
- end
311
+ yield k, v
317
312
  end
318
313
  end
319
314
 
@@ -6,3 +6,12 @@ class String
6
6
  include ::Xqsr3::CommandLineUtilities::MapOptionString
7
7
  end # class String
8
8
 
9
+ class NilClass
10
+
11
+ def map_option_string *args
12
+
13
+ nil
14
+ end
15
+ end
16
+
17
+
@@ -5,13 +5,14 @@
5
5
  # Purpose: Definition of the ParameterChecking module
6
6
  #
7
7
  # Created: 12th February 2015
8
- # Updated: 15th April 2019
8
+ # Updated: 22nd July 2022
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2019-2022, Matthew Wilson and Synesis Information Systems
15
+ # Copyright (c) 2016-2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
17
18
  # Redistribution and use in source and binary forms, with or without
@@ -199,6 +200,22 @@ module ParameterChecking
199
200
  Util_.check_parameter value, name, options, &block
200
201
  end
201
202
 
203
+ # Specific form of the +check_parameter()+ that is used to check
204
+ # options, taking instead the hash and the key
205
+ #
206
+ # === Signature
207
+ #
208
+ # * *Parameters:*
209
+ # - +h+ (::Hash) The options hash from which the named element is to be tested. May not be +nil+
210
+ # - +name+ (::String, ::Symbol, [ ::String, ::Symbol ]) The options key name, or an array of names. May not be +nil+
211
+ # - +options+ (::Hash) options that moderate the behaviour in the same way as for +check_parameter()+ except that the +:treat_as_option+ option (with the value +true+) is merged in before calling +check_parameter()+
212
+ #
213
+ # * *Options:*
214
+ def self.check_option h, name, options = {}, &block
215
+
216
+ Util_.check_option h, name, options, &block
217
+ end
218
+
202
219
  private
203
220
  def Util_.check_option h, names, options = {}, &block
204
221
 
@@ -381,6 +398,7 @@ module ParameterChecking
381
398
  # messages
382
399
 
383
400
  messages = options[:responds_to] || []
401
+ messages = [ messages ] unless messages.respond_to? :each
384
402
 
385
403
  warn "#{self}::check_parameter: options[:responds_to] of type #{messages.class} - should be #{::Array}" unless messages.is_a?(Array)
386
404
  warn "#{self}::check_parameter: options[:responds_to] should contain only symbols or strings" if messages.is_a?(::Array) && !messages.all? { |m| ::Symbol === m || ::String === m }
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: 26th June 2022
8
+ # Updated: 26th July 2022
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -51,7 +51,7 @@
51
51
  module Xqsr3
52
52
 
53
53
  # Current version of the Xqsr3 library
54
- VERSION = '0.37.2'
54
+ VERSION = '0.38.1'
55
55
 
56
56
  private
57
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -35,5 +35,10 @@ class Test_Xqsr3_CommandLineUtilities_map_option_string < Test::Unit::TestCase
35
35
  assert_nil MapOptionString.map_option_string_from_string(shortcut, option_strings)
36
36
  end
37
37
  end
38
+
39
+ def test_nil
40
+
41
+ assert_nil nil.map_option_string []
42
+ end
38
43
  end
39
44
 
@@ -335,7 +335,7 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
335
335
  assert_eql fm1, fm3
336
336
  end
337
337
 
338
- def test_each
338
+ def test_each_WITH_BLOCK
339
339
 
340
340
  fm = FrequencyMap.new
341
341
 
@@ -358,7 +358,25 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
358
358
  assert_equal [:ghi, 2], r[2]
359
359
  end
360
360
 
361
- def test_each_by_key
361
+ def test_each_WITHOUT_BLOCK
362
+
363
+ fm = FrequencyMap.new
364
+
365
+ fm << :def
366
+ fm << :abc << :abc << :abc << :abc
367
+ fm << :ghi << :ghi
368
+
369
+ r = fm.each.to_a
370
+
371
+ r.sort! { |a, b| a[0] <=> b[0] }
372
+
373
+ assert_equal 3, r.size
374
+ assert_equal [:abc, 4], r[0]
375
+ assert_equal [:def, 1], r[1]
376
+ assert_equal [:ghi, 2], r[2]
377
+ end
378
+
379
+ def test_each_by_key_WITH_BLOCK
362
380
 
363
381
  fm = FrequencyMap.new
364
382
 
@@ -379,7 +397,23 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
379
397
  assert_equal [:ghi, 2], r[2]
380
398
  end
381
399
 
382
- def test_each_by_frequency
400
+ def test_each_by_key_WITHOUT_BLOCK
401
+
402
+ fm = FrequencyMap.new
403
+
404
+ fm << :def
405
+ fm << :abc << :abc << :abc << :abc
406
+ fm << :ghi << :ghi
407
+
408
+ r = fm.each_by_key.to_a
409
+
410
+ assert_equal 3, r.size
411
+ assert_equal [:abc, 4], r[0]
412
+ assert_equal [:def, 1], r[1]
413
+ assert_equal [:ghi, 2], r[2]
414
+ end
415
+
416
+ def test_each_by_frequency_WITH_BLOCK
383
417
 
384
418
  fm = FrequencyMap.new
385
419
 
@@ -400,7 +434,23 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
400
434
  assert_equal [:def, 1], r[2]
401
435
  end
402
436
 
403
- def each_value
437
+ def test_each_by_frequency_WITHOUT_BLOCK
438
+
439
+ fm = FrequencyMap.new
440
+
441
+ fm << :def
442
+ fm << :abc << :abc << :abc << :abc
443
+ fm << :ghi << :ghi
444
+
445
+ r = fm.each_by_frequency.to_a
446
+
447
+ assert_equal 3, r.size
448
+ assert_equal [:abc, 4], r[0]
449
+ assert_equal [:ghi, 2], r[1]
450
+ assert_equal [:def, 1], r[2]
451
+ end
452
+
453
+ def test_each_value_WITH_BLOCK
404
454
 
405
455
  fm = FrequencyMap.new
406
456
 
@@ -412,7 +462,7 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
412
462
 
413
463
  fm.each_value do |v|
414
464
 
415
- r << [v]
465
+ r << v
416
466
  end
417
467
 
418
468
  r.sort!
@@ -421,7 +471,7 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
421
471
  assert_equal [1, 2, 4], r
422
472
  end
423
473
 
424
- def each_with_index
474
+ def test_each_value_WITHOUT_BLOCK
425
475
 
426
476
  fm = FrequencyMap.new
427
477
 
@@ -429,19 +479,37 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
429
479
  fm << :abc << :abc << :abc << :abc
430
480
  fm << :ghi << :ghi
431
481
 
432
- fm.each_with_index do |k, v, index|
433
-
434
- case index
435
- when 0
436
- assert_equal :abc, k
437
- assert_equal 2, v
438
- when 1
439
- assert_equal :def, k
440
- assert_equal 1, v
441
- else
442
- assert false, "should never get here"
443
- end
482
+ r = fm.each_value.to_a
483
+
484
+ r.sort!
485
+
486
+ assert_equal 3, r.size
487
+ assert_equal [1, 2, 4], r
488
+ end
489
+
490
+ def test_each_with_index_WITH_BLOCK
491
+
492
+ fm = FrequencyMap.new
493
+
494
+ fm << :def
495
+ fm << :abc << :abc << :abc << :abc
496
+ fm << :ghi << :ghi
497
+
498
+ indexes = []
499
+ kvs = {}
500
+
501
+ fm.each_with_index do |kv, index|
502
+
503
+ k = kv[0]
504
+ v = kv[1]
505
+
506
+ indexes << index
507
+
508
+ kvs[k] = v
444
509
  end
510
+
511
+ assert_equal [ 0, 1, 2 ], indexes
512
+ assert_equal Hash[ :abc, 4, :def, 1, :ghi, 2 ], kvs
445
513
  end
446
514
 
447
515
  def test_empty
@@ -7,13 +7,39 @@ require 'xqsr3/quality/parameter_checking'
7
7
  require 'xqsr3/extensions/test/unit'
8
8
  require 'test/unit'
9
9
 
10
+
11
+ class Test_check_option_multiple_option_names < Test::Unit::TestCase
12
+
13
+ include ::Xqsr3::Quality::ParameterChecking
14
+
15
+ def check_method_stringise_stringize **options
16
+
17
+ check_option options, [ :stringise, :stringize ], nil: true
18
+ end
19
+
20
+ def test_1
21
+
22
+ assert_nil check_method_stringise_stringize()
23
+
24
+ assert_nil check_method_stringise_stringize(abc: :abc)
25
+
26
+ assert_equal :stringize, check_method_stringise_stringize(stringize: :stringize)
27
+ assert_equal :stringise, check_method_stringise_stringize(stringise: :stringise)
28
+ assert_equal :stringise, check_method_stringise_stringize(stringize: :stringize, stringise: :stringise)
29
+ assert_equal :stringise, check_method_stringise_stringize(stringise: :stringise, stringize: :stringize)
30
+ end
31
+ end
32
+
10
33
  class Test_parameter_checks_as_separate_module < Test::Unit::TestCase
11
34
 
12
35
  PC = ::Xqsr3::Quality::ParameterChecking
13
36
 
14
37
  # test 1
15
38
 
16
- def check_method_1 a
39
+ def check_method_1 a, **options
40
+
41
+ PC.check_option options, :o1, nil: true
42
+ PC.check_option options, :o2, nil: false
17
43
 
18
44
  PC.check_param a, 'a'
19
45
  end
@@ -25,10 +51,10 @@ class Test_parameter_checks_as_separate_module < Test::Unit::TestCase
25
51
  check_method_1(nil)
26
52
  end
27
53
 
28
- assert_equal true, check_method_1(true)
29
- assert_equal '', check_method_1('')
30
- assert_equal [], check_method_1([])
31
- assert_equal Hash.new, check_method_1(Hash.new)
54
+ assert_equal true, check_method_1(true, o1: true, o2: false)
55
+ assert_equal '', check_method_1('', o1: true, o2: false)
56
+ assert_equal [], check_method_1([], o1: true, o2: false)
57
+ assert_equal Hash.new, check_method_1(Hash.new, o1: true, o2: false)
32
58
  end
33
59
 
34
60
 
@@ -328,6 +354,11 @@ end
328
354
 
329
355
  check_responds_to Hash.new, [ :this_is_not_a_Hash_method ]
330
356
  end
357
+
358
+ # check can pass single types
359
+ assert check_responds_to Hash.new, :[]
360
+ assert check_responds_to Hash.new, :map
361
+ assert check_responds_to Hash.new, :to_s
331
362
  end
332
363
 
333
364
 
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.37.2
4
+ version: 0.38.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: 2022-06-26 00:00:00.000000000 Z
11
+ date: 2022-07-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