xqsr3 0.8.3

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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +27 -0
  3. data/README.md +26 -0
  4. data/lib/xqsr3/command_line_utilities/map_option_string.rb +137 -0
  5. data/lib/xqsr3/containers/frequency_map.rb +473 -0
  6. data/lib/xqsr3/containers/multi_map.rb +383 -0
  7. data/lib/xqsr3/diagnostics/exception_utilities.rb +216 -0
  8. data/lib/xqsr3/doc_.rb +116 -0
  9. data/lib/xqsr3/extensions/enumerable.rb +4 -0
  10. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +71 -0
  11. data/lib/xqsr3/extensions/enumerable/unique.rb +102 -0
  12. data/lib/xqsr3/extensions/io.rb +3 -0
  13. data/lib/xqsr3/extensions/io/writelines.rb +66 -0
  14. data/lib/xqsr3/extensions/kernel.rb +3 -0
  15. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +68 -0
  16. data/lib/xqsr3/extensions/string.rb +5 -0
  17. data/lib/xqsr3/extensions/string/ends_with.rb +8 -0
  18. data/lib/xqsr3/extensions/string/map_option_string.rb +8 -0
  19. data/lib/xqsr3/extensions/string/starts_with.rb +8 -0
  20. data/lib/xqsr3/extensions/string/to_symbol.rb +8 -0
  21. data/lib/xqsr3/extensions/test/unit.rb +5 -0
  22. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +18 -0
  23. data/lib/xqsr3/extensions/test/unit/assert_not.rb +18 -0
  24. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +18 -0
  25. data/lib/xqsr3/io/writelines.rb +192 -0
  26. data/lib/xqsr3/quality/parameter_checking.rb +343 -0
  27. data/lib/xqsr3/string_utilities/ends_with.rb +134 -0
  28. data/lib/xqsr3/string_utilities/starts_with.rb +127 -0
  29. data/lib/xqsr3/string_utilities/to_symbol.rb +145 -0
  30. data/lib/xqsr3/version.rb +68 -0
  31. data/test/unit/command_line_utilities/tc_map_option_string.rb +39 -0
  32. data/test/unit/command_line_utilities/ts_all.rb +13 -0
  33. data/test/unit/containers/tc_frequency_map.rb +738 -0
  34. data/test/unit/containers/tc_multi_map.rb +640 -0
  35. data/test/unit/containers/ts_all.rb +13 -0
  36. data/test/unit/diagnostics/tc_exception_utilities.rb +221 -0
  37. data/test/unit/diagnostics/ts_all.rb +13 -0
  38. data/test/unit/extensions/enumerable/tc_collect_with_index.rb +36 -0
  39. data/test/unit/extensions/enumerable/tc_unique.rb +47 -0
  40. data/test/unit/extensions/enumerable/ts_all.rb +13 -0
  41. data/test/unit/extensions/io/tc_writelines.rb +110 -0
  42. data/test/unit/extensions/io/ts_all.rb +13 -0
  43. data/test/unit/extensions/kernel/tc_raise_with_options.rb +239 -0
  44. data/test/unit/extensions/kernel/ts_all.rb +13 -0
  45. data/test/unit/extensions/string/tc_ends_with.rb +70 -0
  46. data/test/unit/extensions/string/tc_map_option_string.rb +37 -0
  47. data/test/unit/extensions/string/tc_starts_with.rb +70 -0
  48. data/test/unit/extensions/string/tc_to_symbol.rb +51 -0
  49. data/test/unit/extensions/string/ts_all.rb +13 -0
  50. data/test/unit/extensions/ts_all.rb +13 -0
  51. data/test/unit/io/tc_writelines.rb +200 -0
  52. data/test/unit/io/ts_all.rb +13 -0
  53. data/test/unit/quality/tc_parameter_checking.rb +181 -0
  54. data/test/unit/quality/ts_all.rb +13 -0
  55. data/test/unit/tc_version.rb +37 -0
  56. data/test/unit/ts_all.rb +13 -0
  57. metadata +101 -0
@@ -0,0 +1,134 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/string_utilities/ends_with.rb
4
+ #
5
+ # Purpose: Definition of the ::Xqsr3::StringUtilities::EndsWith
6
+ # module
7
+ #
8
+ # Created: 13th April 2016
9
+ # Updated: 10th June 2016
10
+ #
11
+ # Home: http://github.com/synesissoftware/xqsr3
12
+ #
13
+ # Author: Matthew Wilson
14
+ #
15
+ # Copyright (c) 2016, 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
+ # ##########################################################
49
+ # ::Xqsr3::StringUtilities::EndsWith
50
+
51
+ =begin
52
+ =end
53
+
54
+ module Xqsr3
55
+ module StringUtilities
56
+
57
+ module EndsWith
58
+
59
+ private
60
+ module EndsWith_Helper_ #:nodoc:
61
+
62
+ def self.string_ends_with_helper_ s, prefix
63
+
64
+ if prefix.nil? || prefix.empty?
65
+
66
+ return ''
67
+ elsif prefix.size < s.size
68
+
69
+ return prefix if s[(s.size - prefix.size) ... s.size] == prefix
70
+ elsif prefix.size == s.size
71
+
72
+ return prefix if prefix == s
73
+ else
74
+
75
+ nil
76
+ end
77
+
78
+ nil
79
+ end
80
+
81
+ def self.string_ends_with_array_ s, args
82
+
83
+ return '' if args.empty?
84
+
85
+ args.each do |prefix|
86
+
87
+ case prefix
88
+ when ::NilClass
89
+
90
+ return ''
91
+ when ::String
92
+
93
+ r = self.string_ends_with_helper_ s, prefix
94
+
95
+ return r if r
96
+ else
97
+
98
+ if prefix.respond_to? :to_str
99
+
100
+ return self.string_ends_with_helper_ s.prefix.to_str
101
+ end
102
+
103
+ raise TypeError, "ends_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
104
+ end
105
+ end
106
+
107
+ return nil
108
+ end
109
+ end
110
+ public
111
+
112
+ # Reports on whether a string +s+ ends with a given prefix or set of
113
+ # prefixes (+args+)
114
+ #
115
+ # === *Parameters*
116
+ #
117
+ # * *Required parameters*:
118
+ # - +s+:: [String] The string to be evaluated
119
+ def self.string_ends_with? s, *args
120
+
121
+ EndsWith_Helper_.string_ends_with_array_ s, args
122
+ end
123
+
124
+ def ends_with? *args
125
+
126
+ EndsWith_Helper_.string_ends_with_array_ self, args
127
+ end
128
+ end # module EndsWith
129
+
130
+ end # module StringUtilities
131
+ end # module Xqsr3
132
+
133
+ # ############################## end of file ############################# #
134
+
@@ -0,0 +1,127 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/string_utilities/starts_with.rb
4
+ #
5
+ # Purpose: Definition of the ::Xqsr3::StringUtilities::StartsWith
6
+ # module
7
+ #
8
+ # Created: 13th April 2016
9
+ # Updated: 10th June 2016
10
+ #
11
+ # Home: http://github.com/synesissoftware/xqsr3
12
+ #
13
+ # Author: Matthew Wilson
14
+ #
15
+ # Copyright (c) 2016, 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
+ # ##########################################################
49
+ # ::Xqsr3::StringUtilities::StartsWith
50
+
51
+ =begin
52
+ =end
53
+
54
+ module Xqsr3
55
+ module StringUtilities
56
+
57
+ module StartsWith
58
+
59
+ private
60
+ module StartsWith_Helper_ #:nodoc:
61
+
62
+ def self.string_starts_with_helper_ s, prefix
63
+
64
+ if prefix.nil? || prefix.empty?
65
+
66
+ return ''
67
+ elsif prefix.size < s.size
68
+
69
+ return prefix if s[0 ... prefix.size] == prefix
70
+ elsif prefix.size == s.size
71
+
72
+ return prefix if prefix == s
73
+ else
74
+
75
+ nil
76
+ end
77
+
78
+ nil
79
+ end
80
+
81
+ def self.string_starts_with_array_ s, args
82
+
83
+ return '' if args.empty?
84
+
85
+ args.each do |prefix|
86
+
87
+ case prefix
88
+ when ::NilClass
89
+
90
+ return ''
91
+ when ::String
92
+
93
+ r = self.string_starts_with_helper_ s, prefix
94
+
95
+ return r if r
96
+ else
97
+
98
+ if prefix.respond_to? :to_str
99
+
100
+ return self.string_starts_with_helper_ s.prefix.to_str
101
+ end
102
+
103
+ raise TypeError, "starts_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
104
+ end
105
+ end
106
+
107
+ return nil
108
+ end
109
+ end
110
+ public
111
+
112
+ def self.string_starts_with? s, *args
113
+
114
+ StartsWith_Helper_.string_starts_with_array_ s, args
115
+ end
116
+
117
+ def starts_with? *args
118
+
119
+ StartsWith_Helper_.string_starts_with_array_ self, args
120
+ end
121
+ end # module StartsWith
122
+
123
+ end # module StringUtilities
124
+ end # module Xqsr3
125
+
126
+ # ############################## end of file ############################# #
127
+
@@ -0,0 +1,145 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/string_utilities/to_symbol.rb
4
+ #
5
+ # Purpose: Definition of the ::Xqsr3::StringUtilities::ToSymbol
6
+ # module
7
+ #
8
+ # Created: 14th April 2016
9
+ # Updated: 10th June 2016
10
+ #
11
+ # Home: http://github.com/synesissoftware/xqsr3
12
+ #
13
+ # Author: Matthew Wilson
14
+ #
15
+ # Copyright (c) 2016, 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
+ # ##########################################################
49
+ # ::Xqsr3::StringUtilities::ToSymbol
50
+
51
+ =begin
52
+ =end
53
+
54
+ module Xqsr3
55
+ module StringUtilities
56
+
57
+ # To-symbol conversion facilities
58
+ #
59
+ module ToSymbol
60
+
61
+ private
62
+ module ToSymbol_Helper_ #:nodoc:
63
+
64
+ module Constants #:nodoc:
65
+
66
+ SymbolCharacters0 = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
67
+ SymbolCharactersN = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789'
68
+ end
69
+
70
+ def self.string_to_symbol_with_options_ s, options
71
+
72
+ case s
73
+ when ::String
74
+ ;
75
+ else
76
+
77
+ if s.respond_to? :to_str
78
+
79
+ s = s.to_str
80
+ else
81
+
82
+ raise TypeError, "string argument must be of type #{::String} or a type that will respond to to_str"
83
+ end
84
+ end
85
+
86
+ case options
87
+ when ::Hash
88
+ ;
89
+ else
90
+
91
+ raise TypeError, "options must be of type #{::Hash}, #{options.class} given"
92
+ end
93
+
94
+ return nil if s.empty?
95
+
96
+ transform_characters = options[:transform_characters] || []
97
+
98
+ s.chars.map.with_index do |c, index|
99
+
100
+ if 0 != index && Constants::SymbolCharactersN.include?(c)
101
+
102
+ c
103
+ elsif 0 == index && Constants::SymbolCharacters0.include?(c)
104
+
105
+ c
106
+ else
107
+
108
+ case c
109
+ when '-'
110
+
111
+ return nil if options[:reject_hyphens]
112
+ when ' '
113
+
114
+ return nil if options[:reject_spaces] || options[:reject_whitespace]
115
+ when ?\t
116
+
117
+ return nil if options[:reject_tabs] || options[:reject_whitespace]
118
+ else
119
+
120
+ return nil unless transform_characters.include? c
121
+ end
122
+
123
+ '_'
124
+ end
125
+ end.join('').to_sym
126
+ end
127
+ end
128
+ public
129
+
130
+ def self.string_to_symbol s, options = {}
131
+
132
+ ToSymbol_Helper_.string_to_symbol_with_options_ s, options
133
+ end
134
+
135
+ def to_symbol options = {}
136
+
137
+ ToSymbol_Helper_.string_to_symbol_with_options_ self, options
138
+ end
139
+ end # module ToSymbol
140
+
141
+ end # module StringUtilities
142
+ end # module Xqsr3
143
+
144
+ # ############################## end of file ############################# #
145
+
@@ -0,0 +1,68 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/version.rb
4
+ #
5
+ # Purpose: Version for Xqsr3 library
6
+ #
7
+ # Created: 3rd April 2016
8
+ # Updated: 10th May 2016
9
+ #
10
+ # Home: http://github.com/synesissoftware/xqsr3
11
+ #
12
+ # Author: Matthew Wilson
13
+ #
14
+ # Copyright (c) 2016, 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 Xqsr3
51
+
52
+ # Current version of the Xqsr3 library
53
+ VERSION = '0.8.3'
54
+
55
+ private
56
+ VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
57
+ public
58
+ # Major version of the Xqsr3 library
59
+ VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
60
+ # Minor version of the Xqsr3 library
61
+ VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
62
+ # Revision version of the Xqsr3 library
63
+ VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
64
+
65
+ end # module Xqsr3
66
+
67
+ # ############################## end of file ############################# #
68
+