sixarm_ruby_ramp 2.1.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +1 -1
  4. data/CONTRIBUTING.md +28 -0
  5. data/{README.rdoc → README.md} +112 -42
  6. data/VERSION +1 -1
  7. data/lib/sixarm_ruby_ramp.rb +1 -1
  8. data/lib/sixarm_ruby_ramp/array.rb +39 -16
  9. data/lib/sixarm_ruby_ramp/hash.rb +1 -1
  10. data/lib/sixarm_ruby_ramp/kernel.rb +11 -5
  11. data/lib/sixarm_ruby_ramp/numeric.rb +49 -35
  12. data/lib/sixarm_ruby_ramp/process.rb +5 -20
  13. data/lib/sixarm_ruby_ramp/string.rb +3 -4
  14. data/lib/sixarm_ruby_ramp/xml.rb +0 -204
  15. data/test/sixarm_ruby_ramp_test.rb +2 -2
  16. data/test/sixarm_ruby_ramp_test/array_test.rb +330 -0
  17. data/test/sixarm_ruby_ramp_test/class_test.rb +87 -0
  18. data/test/sixarm_ruby_ramp_test/csv_test.rb +47 -0
  19. data/test/sixarm_ruby_ramp_test/date_test.rb +60 -0
  20. data/test/sixarm_ruby_ramp_test/enumerable_test.rb +303 -0
  21. data/test/sixarm_ruby_ramp_test/file_test.rb +17 -0
  22. data/test/sixarm_ruby_ramp_test/fixnum_test.rb +25 -0
  23. data/test/sixarm_ruby_ramp_test/hash_test.rb +209 -0
  24. data/test/sixarm_ruby_ramp_test/integer_test.rb +21 -0
  25. data/test/sixarm_ruby_ramp_test/io_test.rb +30 -0
  26. data/test/{sixarm_ruby_ramp → sixarm_ruby_ramp_test}/io_test.txt +0 -0
  27. data/test/sixarm_ruby_ramp_test/kernel_test.rb +55 -0
  28. data/test/sixarm_ruby_ramp_test/math_test.rb +19 -0
  29. data/test/sixarm_ruby_ramp_test/nil_test.rb +16 -0
  30. data/test/sixarm_ruby_ramp_test/numeric_test.rb +57 -0
  31. data/test/sixarm_ruby_ramp_test/object_test.rb +13 -0
  32. data/test/sixarm_ruby_ramp_test/process_test.rb +67 -0
  33. data/test/sixarm_ruby_ramp_test/string_test.rb +131 -0
  34. data/test/sixarm_ruby_ramp_test/symbol_test.rb +27 -0
  35. data/test/sixarm_ruby_ramp_test/time_test.rb +29 -0
  36. data/test/sixarm_ruby_ramp_test/xml_test.rb +10 -0
  37. data/test/sixarm_ruby_ramp_test/yaml_test.rb +8 -0
  38. metadata +100 -48
  39. metadata.gz.sig +0 -0
  40. data/CHANGELOG.txt +0 -53
  41. data/INSTALL.txt +0 -32
  42. data/LICENSE.txt +0 -25
  43. data/test/sixarm_ruby_ramp/xml_test_1.xml +0 -5
  44. data/test/sixarm_ruby_ramp/xml_test_2.xml +0 -5
  45. data/test/sixarm_ruby_ramp/xml_test_msword_clean.html +0 -1
  46. data/test/sixarm_ruby_ramp/xml_test_msword_dirty.html +0 -148
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5dbd872b8c2a8f3732dad03323ac18e1e818a7a0
4
+ data.tar.gz: 89e1ed1eb27a9249bb1742f13b50db9e25babe0c
5
+ SHA512:
6
+ metadata.gz: 9636b6fc7048ba889b1f46d5887bf07778045ebd4544ab18a20204e81095b17ea25dd51ed3e3de6b2744d11d301b4597ec91016050ffd3d6792cf46260e70170
7
+ data.tar.gz: 9359784e5fd0ad168d5a618334a06e18b6d4fd8d420654331ea8ff540f09fd5b85d29469665464ce901620fdb1d561d9593a628129c775e7f3f5da585e39ea3a
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ ����YP����F�cU3��X��}���k�ŕE�wd��5�T�U�'e�U�X_*���6���r��D;
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- P�cS�zF�*�C;���?J?�M~�^�&7o1����si$��#pB��Cz=9Bݖ'FDϰ�?c�?V|���m���7*�V��(v���^iN<�%#��U���mR��;ڰ
1
+ X1��L��e��o�
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,28 @@
1
+ # Contributing
2
+
3
+ Thank you for contributing!
4
+
5
+ If you would like to contribute a donation, an easy way is to use PayPal to sixarm@sixarm.com.
6
+
7
+ If you would like to contribute help, the next section is for you.
8
+
9
+
10
+ ## Contributing to the source
11
+
12
+ We love pull requests for improvments to the source code and documentation.
13
+
14
+ There are three easy steps:
15
+
16
+ 1. Fork the repo.
17
+
18
+ * Before you do any work please run our existing tests to make sure the code runs cleanly.
19
+
20
+ 2. Work as you like.
21
+
22
+ * Please create tests. This helps us know that all your code runs cleanly.
23
+
24
+ 3. Push to your fork and submit a pull request.
25
+
26
+ * We'll take a look as soon as we can; this is typically within a business day.
27
+
28
+ Thank you again!
@@ -1,24 +1,57 @@
1
- = SixArm.com » Ruby » Ramp gem is a toolkit of Ruby base class extensions
1
+ # SixArm.com » Ruby » <br> Ramp gem is a toolkit of Ruby base class extensions
2
2
 
3
- Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
4
- Copyright:: Copyright (c) 2006-2012 Joel Parker Henderson
5
- License:: See LICENSE.txt file
3
+ * Doc: <http://sixarm.com/sixarm_ruby_ramp/doc>
4
+ * Gem: <http://rubygems.org/gems/sixarm_ruby_ramp>
5
+ * Repo: <http://github.com/sixarm/sixarm_ruby_ramp>
6
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
6
7
 
7
- Ramp is a library of extensions to Ruby base classes, including Array, Date, Enumerable, Hash, Kernel, Numeric, Object, Process, String, Time, and YAML.
8
8
 
9
- Testing:
9
+ ## Introduction
10
10
 
11
- * Each has an associated test class, e.g., ArrayTest, DateTest, etc.
12
- * The easy way to run the tests: gem install sixarm_ruby_ramp --test
11
+ Ramp is a library of extensions to Ruby base classes.
13
12
 
13
+ We extend Array, Date, Enumerable, Hash, Kernel, Numeric, Object, Process, String, Time, and YAML.
14
14
 
15
- == Array
15
+ For docs go to <http://sixarm.com/sixarm_ruby_ramp/doc>
16
+
17
+ Want to help? We're happy to get pull requests.
18
+
19
+
20
+ ## Install quickstart
21
+
22
+ Install:
23
+
24
+ gem install sixarm_ruby_ramp
25
+
26
+ Bundler:
27
+
28
+ gem "sixarm_ruby_ramp", "~>3.0.0"
29
+
30
+ Require:
31
+
32
+ require "sixarm_ruby_ramp"
33
+
34
+
35
+ ## Install with security (optional)
36
+
37
+ To enable high security for all our gems:
38
+
39
+ wget http://sixarm.com/sixarm.pem
40
+ gem cert --add sixarm.pem
41
+ gem sources --add http://sixarm.com
42
+
43
+ To install with high security:
44
+
45
+ gem install sixarm_ruby_ramp --test --trust-policy HighSecurity
46
+
47
+
48
+ ## Array
16
49
 
17
50
  * car, cdr: aka first, rest (see shifted)
18
51
  * choice, choices: one or more random elements from an array
19
52
  * cross: return the cross pairings of an array with another array
20
53
  * divvy: divides an array, like a pie, into a specified number of slices (deprecated - see method rdoc)
21
- * join: same as Array#join with some improvments
54
+ * join, join_prefix_suffix, join_prefix_suffix_infix: like Array#join with improvements
22
55
  * onto: return a hash that maps an array's keys on to another array's values
23
56
  * rotate: moves the first element of an array to the end
24
57
  * rest: return the rest of the items of the array (aka cdr, aka shifted)
@@ -31,17 +64,17 @@ Testing:
31
64
  * union: builds an array containing each of the unique elements of sub-arrays ([[1,2,3,4],[2,3,4,5],[3,4,5,6]].union => [1,2,3,4,5,6])
32
65
 
33
66
 
34
- == Class
67
+ ## Class
35
68
 
36
69
  * publicize_methods: make all methods public for a block, e.g. to unit test private methods
37
70
 
38
71
 
39
- == CSV
72
+ ## CSV
40
73
 
41
74
  * http_headers: provides web file download headers for text/csv content type and disposition.
42
75
 
43
76
 
44
- == Date
77
+ ## Date
45
78
 
46
79
  * age_days, age_years
47
80
  * between: a random date between two specified dates
@@ -49,7 +82,7 @@ Testing:
49
82
  * weekday?, weekend?: is date a weekday or on the weekend
50
83
 
51
84
 
52
- == Enumerable
85
+ ## Enumerable
53
86
 
54
87
  * cartesian_product: return an array of all possible ordered tuples from arrays.
55
88
  * hash_by: convert the array to a hash by mapping each item to a key=>value pair.
@@ -64,18 +97,18 @@ Testing:
64
97
  * power_set: return an array with all subsets of the enum's elements
65
98
 
66
99
 
67
- == File
100
+ ## File
68
101
 
69
102
  * File.joindir: wrapper for File.join(File.dirname(...),string,...)
70
103
 
71
104
 
72
- == Fixnum
105
+ ## Fixnum
73
106
 
74
107
  * even?: is the number even?
75
108
  * odd?: is the number odd?
76
109
 
77
110
 
78
- == Hash
111
+ ## Hash
79
112
 
80
113
  * size?: return true if hash has any keys
81
114
  * sort_by_keys: return a new Hash sorted by keys
@@ -87,48 +120,49 @@ Testing:
87
120
  * pivot: aggregates subtotals by keys and values, such as a rollup and rolldown
88
121
 
89
122
 
90
- == Integer
123
+ ## Integer
91
124
 
92
125
  * maps: syntactic sugar to yield n times to a block, returning an array of any results
93
126
  * odd?: is the number odd?
94
127
 
95
128
 
96
- == IO
129
+ ## IO
97
130
 
98
131
  * readrow: reads a row line as with IO#readline, and return the row split it into fields
99
132
  * IO.readrows: reads the entire file specified by name as individual row lines, and return those rows split into fields, in an array of arrays.
100
133
 
101
134
 
102
- == Kernel
135
+ ## Kernel
103
136
 
104
137
  * my_method_name: return the name of the current method
105
138
  * caller_method_name: return the name of the caller method, or the Nth parent up the call stack if the optional caller_index parameter is passed.
106
139
 
107
140
 
108
- == Math
141
+ ## Math
109
142
 
110
143
  * ln(x): natural log of x
111
144
  * logn(x,b): log of x in base b
112
145
 
113
146
 
114
- == NilClass
147
+ ## NilClass
115
148
 
116
149
  * blank?: return true (same as Rails)
117
150
 
118
151
 
119
- == Numeric
152
+ ## Numeric
120
153
 
121
154
  * if: return 0 if the passed flag is any of: nil, false, 0, [], {} and otherwise return self
122
155
  * unless: return 0 unless the passed flag is any of: nil, false, 0, [], {} and otherwise return self
123
156
  * percent: return the number as a percentage with optional rounding to decimal points
157
+ * floor_precision: return the number truncated to a given precision, i.e. decimal points
124
158
 
125
159
 
126
- == Object
160
+ ## Object
127
161
 
128
162
  * in?: return boolean indicating whether the object is a member of the specified array parameter
129
163
 
130
164
 
131
- == Process
165
+ ## Process
132
166
 
133
167
  Extensions that help debug Ruby programs.
134
168
 
@@ -136,22 +170,22 @@ Extensions that help debug Ruby programs.
136
170
  * (class) pss: output of the system 'ps' command as a hash with each value set to the right type, e.g., integer, float, etc..
137
171
 
138
172
 
139
- == REXML::Attributes
173
+ ## REXML::Attributes
140
174
 
141
175
  * hash: flattens the attributes hash set into a more useful ruby hash, e.g. {:height => 100, :width => 400 }
142
176
 
143
177
 
144
- == REXML::Document
178
+ ## REXML::Document
145
179
 
146
180
  * remove_attributes: remove all the attributes from the document's elements
147
181
 
148
182
 
149
- == REXML::Element
183
+ ## REXML::Element
150
184
 
151
185
  * remove_attributes: remove all the attributes from the element
152
186
 
153
187
 
154
- == String
188
+ ## String
155
189
 
156
190
  * capitalize_words (alias to titleize/titlecase): ensures the first character of each word is uppercase.
157
191
  * decrement: decrease the rightmost natural number, defaults to one value lower or by the optional step parameter value.
@@ -167,30 +201,66 @@ Extensions that help debug Ruby programs.
167
201
  * words: split the string into an array of words
168
202
 
169
203
 
170
- == Symbol
204
+ ## Symbol
171
205
 
172
206
  * <=> and include the comparable mixin to compare symbols as strings
173
207
 
174
208
 
175
- == Time
209
+ ## Time
176
210
 
177
211
  * (class) stamp: current time in UTC as a timestamp string ("YYYYMMDDHHMMSS")
178
212
  * to_sql: time as a string formatted as expected for MySQL
179
213
 
180
214
 
181
- == XML
182
-
183
- * (class) load_dir: specify a one or more directory patterns and pass each XML file in the matching directories to a block; see [Dir#glob](http://www.ruby-doc.org/core/classes/Dir.html#M002347) for pattern details.
184
- * (class) strip_all: delete exraneous junk from an XML text string, typically for sanitizing input
185
- * (class) strip_attributes: delete all attributes from an XML text string
186
- * (class) strip_comments: delete all comments from an XML text string
187
- * (class) strip_microsoft: delete all proprietary Microsoft code from an XML text string
188
- * (class) strip_unprintables: delete all unprintable characters from an XML text string
189
-
190
-
191
- == YAML
215
+ ## YAML
192
216
 
193
217
  * (class) load_dir: specify directory patterns and pass each YAML file in the matching directories to a block; see [Dir#glob](http://www.ruby-doc.org/core/classes/Dir.html#M002347) for pattern details.
194
218
  * (class) load_dir_pairs: specify directory patterns and pass each YAML file in the matching directories to a block to process key/value pairs.
195
219
 
196
220
 
221
+ ## Changes
222
+
223
+ * 2013-08-18 3.0.0 Upgrade to Ruby 2
224
+ * 2012-09-01 2.1.7 Add Numeric#floor_precision
225
+ * 2012-03-14 2.1.6 Update docs, tests
226
+ * 2.1.6 Refactor XML#strip* methods to new sixarm_ruby_xml_strip gem.
227
+ * 2.1.5 Refactor XML#load* methods to new sixarm_ruby_xml_load gem.
228
+ * 2.1.4 Refactor REXML extensions to new sixarm_ruby_rexml gem.
229
+ * 2.1.3 Remove dependency on sixarm_ruby_array_slice
230
+ * 2.1.2 Refactor Array#slices and #divvy to sixarm_ruby_array_slice gem with better method names.
231
+ * 2.1.0 Upgrades for Ruby 1.9.3; better README, new CHANGELOG, less YAML, etc.
232
+ * 2.0.x Upgrades for Ruby 1.9.2; add methods; lift some methods to their own gems
233
+ * 1.8.x 100% rcov coverage; add methods
234
+ * 1.7.x Enable gemcutter; add methods; remove sqlite dependency
235
+ * 1.6.x Upgrades for Ruby 1.9.1; improve structure; add methods
236
+ * 1.5.0 Combined all Ruby extension files into one gem
237
+ * 1.0.0 Original
238
+
239
+
240
+ ## License
241
+
242
+ You may choose any of these open source licenses:
243
+
244
+ * Apache License
245
+ * BSD License
246
+ * CreativeCommons License, Non-commercial Share Alike
247
+ * GNU General Public License Version 2 (GPL 2)
248
+ * GNU Lesser General Public License (LGPL)
249
+ * MIT License
250
+ * Perl Artistic License
251
+ * Ruby License
252
+
253
+ The software is provided "as is", without warranty of any kind,
254
+ express or implied, including but not limited to the warranties of
255
+ merchantability, fitness for a particular purpose and noninfringement.
256
+
257
+ In no event shall the authors or copyright holders be liable for any
258
+ claim, damages or other liability, whether in an action of contract,
259
+ tort or otherwise, arising from, out of or in connection with the
260
+ software or the use or other dealings in the software.
261
+
262
+ This license is for the included software that is created by SixArm;
263
+ some of the included software may have its own licenses, copyrights,
264
+ authors, etc. and these do take precedence over the SixArm license.
265
+
266
+ Copyright (c) 2005-2012 Joel Parker Henderson
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.3
1
+ 3.0.0
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin rdoc
3
- Please see README.rdoc
3
+ Please see README
4
4
  =end
5
5
 
6
6
  ['array','class','csv','date','enumerable','file','fixnum','hash','integer','io','kernel','math','nil','numeric','object','process','string','symbol','time','xml','yaml'].map{|x|
@@ -16,39 +16,62 @@ class Array
16
16
  #
17
17
  # @return [String] concatenated string
18
18
  #
19
- # @example Typical Array#join with infix
19
+ # @example Join with infix
20
20
  # list=['a','b','c']
21
21
  # list.join("*") => "a*b*c"
22
22
  #
23
- # @example Improved join with infix, prefix, suffix
23
+ # @example Join with prefix and suffix
24
24
  # list=['a','b','c']
25
- # list.join("*","[","]") => "[a]*[b]*[c]"
25
+ # list.join("[","]") => "[a][b][c]"
26
26
  #
27
- # @example Improved join with just prefix and suffix
27
+ # @example Join with prefix, suffix, and infix
28
28
  # list=['a','b','c']
29
- # list.join("[","]") => "[a][b][c]"
30
-
29
+ # list.join("*","[","]") => "[a]*[b]*[c]"
30
+ #
31
31
  def join(*fixes)
32
32
  if fixes.is_a?(String) then return self.ruby_join(fixes) end
33
- case fixes.size
33
+ return case fixes.size
34
34
  when 0
35
- return self.ruby_join()
35
+ ruby_join
36
36
  when 1
37
- return self.ruby_join(fixes[0])
37
+ ruby_join(fixes[0].to_s)
38
38
  when 2
39
- prefix=fixes[0].to_s
40
- suffix=fixes[1].to_s
41
- return self.map{|item| prefix + item.to_s + suffix}.ruby_join()
39
+ join_prefix_suffix(*fixes)
42
40
  when 3
43
- infix =fixes[0].to_s
44
- prefix=fixes[1].to_s
45
- suffix=fixes[2].to_s
46
- return self.map{|item| prefix + item.to_s + suffix}.ruby_join(infix)
41
+ join_prefix_suffix_infix(*fixes)
47
42
  else
48
43
  raise ArgumentError, "join() takes 0-3 arguments; you gave #{fixes.size}]"
49
44
  end
50
45
  end
51
46
 
47
+ # Concatenate the items by joining using a prefix string and suffix string.
48
+ #
49
+ # @return [String] concatenated string
50
+ #
51
+ # @example
52
+ # list=['a','b','c']
53
+ # list.join("[","]") => "[a][b][c]"
54
+ #
55
+ def join_prefix_suffix(prefix, suffix)
56
+ prefix = prefix.to_s
57
+ suffix = suffix.to_s
58
+ return self.map{|item| prefix + item.to_s + suffix}.ruby_join()
59
+ end
60
+
61
+ # Concatenate the items by joining using a prefix string, suffix string, and infix string.
62
+ #
63
+ # @return [String] concatenated string
64
+ #
65
+ # @example
66
+ # list=['a','b','c']
67
+ # list.join("*","[","]") => "[a]*[b]*[c]"
68
+ #
69
+ def join_prefix_suffix_infix(prefix, suffix, infix)
70
+ prefix = prefix.to_s
71
+ suffix = suffix.to_s
72
+ infix = infix.to_s
73
+ return self.map{|item| prefix + item.to_s + suffix}.ruby_join(infix)
74
+ end
52
75
 
53
76
  # @return [Boolean] true if size > 0
54
77
  #
@@ -169,7 +169,7 @@ class Hash
169
169
  # "Developers"=>198
170
170
  # }
171
171
  #
172
- # Generic xxample:
172
+ # Generic example:
173
173
  # h={
174
174
  # "a"=>{"x"=>1,"y"=>2,"z"=>3},
175
175
  # "b"=>{"x"=>4,"y"=>5,"z"=>6},
@@ -10,11 +10,13 @@ module Kernel
10
10
  # - http://www.ruby-forum.com/topic/75258
11
11
  # - In 1.9 (Ruby CVS HEAD) there is #__method__ and #__callee__
12
12
  # - http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l90
13
- #-
13
+ #
14
+ # See http://stackoverflow.com/questions/5100299/how-to-get-the-name-of-the-calling-method
15
+ #
14
16
  # Make this fast because its often doing logging & reporting.
15
17
  # Inline this and use $1 because it's empirically faster than /1
16
18
  #
17
- # These two methods are always equal:
19
+ # These two methods must always be equal:
18
20
  # caller_method_name(0) === my_method_name
19
21
  #
20
22
  # @example
@@ -27,7 +29,9 @@ module Kernel
27
29
  # @return [String] my method name
28
30
 
29
31
  def my_method_name
30
- caller[0] =~ /`([^']*)'/ and $1
32
+ RUBY_VERSION > '2.0' \
33
+ ? caller_locations(1,1).first.base_label \
34
+ : caller[0][/`([^']*)'/, 1]
31
35
  end
32
36
 
33
37
 
@@ -39,7 +43,7 @@ module Kernel
39
43
  # Make this fast because its often doing logging & reporting.
40
44
  # Inline this and use $1 because it's empirically faster than /1
41
45
  #
42
- # These two methods are always equal:
46
+ # These two methods must always be equal:
43
47
  # caller_method_name(0) === my_method_name
44
48
  #
45
49
  # @example
@@ -54,7 +58,9 @@ module Kernel
54
58
  # @return [String] the method name of the caller at the index
55
59
 
56
60
  def caller_method_name(caller_index=0)
57
- caller[caller_index] =~ /`([^']*)'/ and $1
61
+ RUBY_VERSION > '2.0' \
62
+ ? caller_locations(caller_index + 1,1).first.base_label \
63
+ : caller[caller_index][/`([^']*)'/, 1]
58
64
  end
59
65
 
60
66