xqsr3 0.16.1 → 0.17.2

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: f1b3bde5f5924163f03e47dd630d7a66fefc7b2b
4
- data.tar.gz: 250d145c6f4e5df5ec8cf6da99ac4eeada2da5e3
3
+ metadata.gz: 18672bcef5bd6994d1ff9c2dc5be6289ca79042e
4
+ data.tar.gz: cc79b90f538dbdc1273853d73d4b13cea0fab110
5
5
  SHA512:
6
- metadata.gz: 4a6d515ae16aa93e7815212fae3a869fa90e94b5fc19ed455dab28e1c5e154c11521317e590b7c30f1394a9a44ff25ae714ceb35fa8df3479d118d8562578456
7
- data.tar.gz: 41df1e79b7ca6dfb5d498f333ae7099d1d40a4411aab9ce179790ad391aae21292b7df6e8327f23e8208a8f3b58b9fbccc7a76962801cd44c53d8e469208a15b
6
+ metadata.gz: 16ae7d901c5ef0a916497c34fb9edfb342c0f774071a1b6f3de6a922c452d1de639caee0e587c18e566a7164b4b5303dff2ab09acb03624dc4edcb1df954cde4
7
+ data.tar.gz: d77073d7e4fdcc461c75b5ab6d2e522573f113647b72cf7db16e3e7c8c209403cb37d5bbac96fda35cf697594f84b0ae88864e06a975785f7cbd6838de5352a6
@@ -0,0 +1,97 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/extensions/enumerable/detect_map.rb
4
+ #
5
+ # Purpose: ::Enumerable#detect_map extension
6
+ #
7
+ # Created: 3rd December 2017
8
+ # Updated: 9th December 2017
9
+ #
10
+ # Home: http://github.com/synesissoftware/xqsr3
11
+ #
12
+ # Author: Matthew Wilson
13
+ #
14
+ # Copyright (c) 2017, Matthew Wilson and Synesis Software
15
+ # All rights reserved.
16
+ #
17
+ # Redistribution and use in source and binary forms, with or without
18
+ # modification, are permitted provided that the following conditions are
19
+ # met:
20
+ #
21
+ # * Redistributions of source code must retain the above copyright
22
+ # notice, this list of conditions and the following disclaimer.
23
+ #
24
+ # * Redistributions in binary form must reproduce the above copyright
25
+ # notice, this list of conditions and the following disclaimer in the
26
+ # documentation and/or other materials provided with the distribution.
27
+ #
28
+ # * Neither the names of the copyright holder nor the names of its
29
+ # contributors may be used to endorse or promote products derived from
30
+ # this software without specific prior written permission.
31
+ #
32
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
33
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
34
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
36
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
+ #
44
+ # ######################################################################## #
45
+
46
+
47
+ =begin
48
+ =end
49
+
50
+ module Enumerable
51
+
52
+ # The +Enumerable#detect+ method provides a way to detect the presence
53
+ # of a particular value in a collection. The only constraint is that you
54
+ # get back the object unchanged.
55
+ #
56
+ # The +Enumerable#map+ method provides a way to transform the contents of
57
+ # a collection. The only constraint is that you get back another
58
+ # collection.
59
+ #
60
+ # This extension method, +Enumerable#detect_map+ combines the features
61
+ # of both, in that it detects the presence of a particular value in a
62
+ # collection and transform the detected value.
63
+ #
64
+ # [ 1, 2, 3 ].detect_map { |v| -2 * v if v > 2 } # => -6
65
+ #
66
+ # { :ab => 'cd', :ef => 'gh' }.detect_map { |k, v| v.upcase if k == :ef } # => 'GH'
67
+ #
68
+ # @note The block is required (for technical reasons), and must have
69
+ # arity 1 for sequences or 2 for associations
70
+ def detect_map &block
71
+
72
+ case block.arity
73
+ when 1
74
+
75
+ self.each do |v|
76
+
77
+ r = yield(v) and return r
78
+ end
79
+ when 2
80
+
81
+ self.each do |k, v|
82
+
83
+ r = yield(k, v) and return r
84
+ end
85
+ else
86
+
87
+ raise ArgumentError, "detect_map requires block with arity of 1 (for sequences) or 2 (for associations); block with arity #{block.arity} given to instance of #{self.class}"
88
+ end
89
+
90
+ nil
91
+ end
92
+
93
+ end # module Enumerable
94
+
95
+ # ############################## end of file ############################# #
96
+
97
+
@@ -5,7 +5,7 @@
5
5
  # Purpose: Definition of the ParameterChecking module
6
6
  #
7
7
  # Created: 12th February 2015
8
- # Updated: 7th December 2017
8
+ # Updated: 16th December 2017
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -76,26 +76,7 @@ module ParameterChecking
76
76
 
77
77
  def self.included base
78
78
 
79
-
80
- base.class_eval do
81
-
82
- def self.check_parameter value, name, options = {}, &block
83
-
84
- Util_.check_parameter value, name, options, &block
85
- end
86
-
87
- # @see check_parameter
88
- #
89
- # @note This is obsolete, and will be removed in a future
90
- # version. Please use +check_parameter+ instead
91
- def self.check_param value, name, options = {}, &block
92
-
93
- Util_.check_parameter value, name, options, &block
94
- end
95
-
96
- private_class_method :check_param
97
- private_class_method :check_parameter
98
- end
79
+ base.extend self
99
80
  end
100
81
 
101
82
  # Check a given parameter (value=+value+, name=+name+) for type and value
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: 7th December 2017
8
+ # Updated: 16th December 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.16.1'
53
+ VERSION = '0.17.2'
54
54
 
55
55
  private
56
56
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -0,0 +1,43 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
4
+
5
+ require 'xqsr3/extensions/enumerable/detect_map'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+
9
+ require 'test/unit'
10
+
11
+ class Test_Enumerable_detect_map < Test::Unit::TestCase
12
+
13
+ def test_with_array
14
+
15
+ assert_nil [].detect_map { |v| nil }
16
+ assert_nil [ 1, 2, 3, 4, 5 ].detect_map { |v| nil }
17
+
18
+ assert_nil [].detect_map { |v| :nil }
19
+ assert_not_nil [ 1, 2, 3, 4, 5 ].detect_map { |v| :nil }
20
+
21
+ assert_nil [].detect_map { |v| return -2 * v }
22
+ assert_equal -2, [ 1, 2, 3, 4, 5 ].detect_map { |v| -2 * v }
23
+ assert_equal(-4, [ 1, 2, 3, 4, 5 ].detect_map { |v| -2 * v if 2 == v })
24
+ end
25
+
26
+ def test_with_hash
27
+
28
+ h1 = {}
29
+ h2 = { :abc => 'def', :ghi => 'jkl' }
30
+
31
+ assert_nil h1.detect_map { |k, v| nil }
32
+ assert_nil h2.detect_map { |k, v| nil }
33
+
34
+ assert_nil h1.detect_map { |k, v| :nil }
35
+ assert_not_nil h2.detect_map { |k, v| :nil }
36
+
37
+ assert_nil h1.detect_map { |k, v| v.upcase }
38
+ assert_equal 'DEF', h2.detect_map { |k, v| v.upcase }
39
+ assert_equal 'JKL', h2.detect_map { |k, v| v.upcase if :ghi == k }
40
+ end
41
+ end
42
+
43
+
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.16.1
4
+ version: 0.17.2
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-12-07 00:00:00.000000000 Z
11
+ date: 2017-12-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,8 +19,6 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - LICENSE
23
- - README.md
24
22
  - lib/xqsr3/array_utilities/join_with_or.rb
25
23
  - lib/xqsr3/command_line_utilities/map_option_string.rb
26
24
  - lib/xqsr3/containers/frequency_map.rb
@@ -29,36 +27,37 @@ files:
29
27
  - lib/xqsr3/diagnostics/exception_utilities.rb
30
28
  - lib/xqsr3/doc_.rb
31
29
  - lib/xqsr3/extensions/array/join_with_or.rb
32
- - lib/xqsr3/extensions/enumerable.rb
33
30
  - lib/xqsr3/extensions/enumerable/collect_with_index.rb
31
+ - lib/xqsr3/extensions/enumerable/detect_map.rb
34
32
  - lib/xqsr3/extensions/enumerable/unique.rb
35
- - lib/xqsr3/extensions/hash.rb
33
+ - lib/xqsr3/extensions/enumerable.rb
36
34
  - lib/xqsr3/extensions/hash/deep_transform.rb
37
35
  - lib/xqsr3/extensions/hash/has_match.rb
38
36
  - lib/xqsr3/extensions/hash/match.rb
39
- - lib/xqsr3/extensions/io.rb
37
+ - lib/xqsr3/extensions/hash.rb
40
38
  - lib/xqsr3/extensions/io/writelines.rb
41
- - lib/xqsr3/extensions/kernel.rb
39
+ - lib/xqsr3/extensions/io.rb
42
40
  - lib/xqsr3/extensions/kernel/integer.rb
43
41
  - lib/xqsr3/extensions/kernel/raise_with_options.rb
44
- - lib/xqsr3/extensions/string.rb
42
+ - lib/xqsr3/extensions/kernel.rb
45
43
  - lib/xqsr3/extensions/string/ends_with.rb
46
44
  - lib/xqsr3/extensions/string/map_option_string.rb
47
45
  - lib/xqsr3/extensions/string/quote_if.rb
48
46
  - lib/xqsr3/extensions/string/starts_with.rb
49
47
  - lib/xqsr3/extensions/string/to_bool.rb
50
48
  - lib/xqsr3/extensions/string/to_symbol.rb
51
- - lib/xqsr3/extensions/test/unit.rb
49
+ - lib/xqsr3/extensions/string.rb
52
50
  - lib/xqsr3/extensions/test/unit/assert_eql.rb
53
51
  - lib/xqsr3/extensions/test/unit/assert_false.rb
54
52
  - lib/xqsr3/extensions/test/unit/assert_not.rb
55
53
  - lib/xqsr3/extensions/test/unit/assert_not_eql.rb
56
54
  - lib/xqsr3/extensions/test/unit/assert_true.rb
55
+ - lib/xqsr3/extensions/test/unit.rb
57
56
  - lib/xqsr3/hash_utilities/deep_transform.rb
58
57
  - lib/xqsr3/hash_utilities/key_matching.rb
59
58
  - lib/xqsr3/io/writelines.rb
60
- - lib/xqsr3/quality.rb
61
59
  - lib/xqsr3/quality/parameter_checking.rb
60
+ - lib/xqsr3/quality.rb
62
61
  - lib/xqsr3/string_utilities/ends_with.rb
63
62
  - lib/xqsr3/string_utilities/quote_if.rb
64
63
  - lib/xqsr3/string_utilities/starts_with.rb
@@ -77,6 +76,7 @@ files:
77
76
  - test/unit/diagnostics/tc_exception_utilities.rb
78
77
  - test/unit/diagnostics/ts_all.rb
79
78
  - test/unit/extensions/enumerable/tc_collect_with_index.rb
79
+ - test/unit/extensions/enumerable/tc_detect_map.rb
80
80
  - test/unit/extensions/enumerable/tc_unique.rb
81
81
  - test/unit/extensions/enumerable/ts_all.rb
82
82
  - test/unit/extensions/hash/tc_deep_transform.rb
@@ -106,6 +106,8 @@ files:
106
106
  - test/unit/xml/ts_all.rb
107
107
  - test/unit/xml/utilities/tc_compare.rb
108
108
  - test/unit/xml/utilities/ts_all.rb
109
+ - README.md
110
+ - LICENSE
109
111
  homepage: http://github.com/synesissoftware/xqsr3
110
112
  licenses:
111
113
  - 3-clause BSD
@@ -126,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
128
  version: '0'
127
129
  requirements: []
128
130
  rubyforge_project:
129
- rubygems_version: 2.4.2
131
+ rubygems_version: 2.0.14.1
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: xqsr3