webget_ruby_ramp 1.8.0 → 1.8.2
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.
- data.tar.gz.sig +2 -2
- data/README.rdoc +24 -7
- data/lib/webget_ruby_ramp.rb +2 -2
- data/lib/webget_ruby_ramp/array.rb +56 -43
- data/lib/webget_ruby_ramp/class.rb +3 -1
- data/lib/webget_ruby_ramp/csv.rb +4 -4
- data/lib/webget_ruby_ramp/date.rb +12 -12
- data/lib/webget_ruby_ramp/enumerable.rb +101 -46
- data/lib/webget_ruby_ramp/file.rb +2 -2
- data/lib/webget_ruby_ramp/fixnum.rb +4 -7
- data/lib/webget_ruby_ramp/hash.rb +18 -15
- data/lib/webget_ruby_ramp/integer.rb +8 -7
- data/lib/webget_ruby_ramp/io.rb +24 -20
- data/lib/webget_ruby_ramp/kernel.rb +32 -0
- data/lib/webget_ruby_ramp/math.rb +10 -2
- data/lib/webget_ruby_ramp/nil.rb +5 -2
- data/lib/webget_ruby_ramp/numeric.rb +5 -71
- data/lib/webget_ruby_ramp/object.rb +4 -3
- data/lib/webget_ruby_ramp/process.rb +54 -7
- data/lib/webget_ruby_ramp/string.rb +54 -24
- data/lib/webget_ruby_ramp/symbol.rb +16 -0
- data/lib/webget_ruby_ramp/time.rb +19 -11
- data/lib/webget_ruby_ramp/xml.rb +30 -20
- data/lib/webget_ruby_ramp/yaml.rb +5 -4
- data/test/webget_ruby_ramp/numeric_test.rb +0 -60
- data/test/webget_ruby_ramp/string_test.rb +0 -5
- metadata +2 -2
- metadata.gz.sig +1 -1
data.tar.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
�]x̸4�B^���xf!�8�B��?�_��YӌJł���i�f]>$���h#mF�%��+ciW� .�:^���6*�|��?�F{W�=Ut����}p�J��3�\���Z����8㎫���s��YW
|
2
|
+
G}
|
data/README.rdoc
CHANGED
@@ -9,8 +9,10 @@ License:: LGPL, GNU Lesser General Public License
|
|
9
9
|
Ramp is a library of extensions to Ruby base classes, including Array, Date, Enumerable, Hash, Kernel, Numeric, Object, Process, String, Time, and YAML.
|
10
10
|
|
11
11
|
Testing:
|
12
|
-
|
13
|
-
|
12
|
+
<ul>
|
13
|
+
<li>Each has an associated test class, e.g., ArrayTest, DateTest, etc.
|
14
|
+
<li>The easy way to run the tests: gem install webget_ruby_ramp --test
|
15
|
+
</ul>
|
14
16
|
|
15
17
|
|
16
18
|
== Array
|
@@ -32,6 +34,11 @@ Testing:
|
|
32
34
|
* 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])
|
33
35
|
|
34
36
|
|
37
|
+
== Class
|
38
|
+
|
39
|
+
* publicize_methods: make all methods public for a block, e.g. to unit test private methods
|
40
|
+
|
41
|
+
|
35
42
|
== CSV
|
36
43
|
|
37
44
|
* http_headers: provides web file download headers for text/csv content type and disposition.
|
@@ -65,6 +72,12 @@ Testing:
|
|
65
72
|
* File.joindir: wrapper for File.join(File.dirname(...),string,...)
|
66
73
|
|
67
74
|
|
75
|
+
== Fixnum
|
76
|
+
|
77
|
+
* even?: is the number even?
|
78
|
+
* odd?: is the number odd?
|
79
|
+
|
80
|
+
|
68
81
|
== Hash
|
69
82
|
|
70
83
|
* size?: return true if hash has any keys
|
@@ -79,7 +92,8 @@ Testing:
|
|
79
92
|
|
80
93
|
== Integer
|
81
94
|
|
82
|
-
* maps: syntactic sugar to yield n times to a block, returning an array of any results
|
95
|
+
* maps: syntactic sugar to yield n times to a block, returning an array of any results
|
96
|
+
* odd?: is the number odd?
|
83
97
|
|
84
98
|
|
85
99
|
== IO
|
@@ -90,8 +104,8 @@ Testing:
|
|
90
104
|
|
91
105
|
== Kernel
|
92
106
|
|
93
|
-
*
|
94
|
-
*
|
107
|
+
* my_method_name: returns the name of the current method
|
108
|
+
* caller_method_name: returns the name of the caller method, or the Nth parent up the call stack if the optional caller_index parameter is passed.
|
95
109
|
|
96
110
|
|
97
111
|
== Math
|
@@ -109,7 +123,6 @@ Testing:
|
|
109
123
|
|
110
124
|
* if: returns 0 if the passed flag is any of: nil, false, 0, [], {} and otherwise returns self
|
111
125
|
* unless: returns 0 unless the passed flag is any of: nil, false, 0, [], {} and otherwise returns self
|
112
|
-
* peta, tera, giga, mega, kilo, hecto, deka, deci, centi, milli, micro, nano: multiply/divide by powers of ten
|
113
126
|
|
114
127
|
|
115
128
|
== Object
|
@@ -184,7 +197,11 @@ Extensions that help debug Ruby programs.
|
|
184
197
|
|
185
198
|
== Changes
|
186
199
|
|
187
|
-
- 1.
|
200
|
+
- 1.8.2 Refactored Numeric metric names into their own methods
|
201
|
+
- 1.8.0 100% rcov coverage
|
202
|
+
- 1.7.8 Add rcov testing
|
203
|
+
- 1.7.4 Add Class#publicize_methods, Integer#even?, Integer#odd?
|
204
|
+
- 1.7.3 Refactor Rails classes to their own gem, add README, LICENSE
|
188
205
|
- 1.7.2 Gemcutter update
|
189
206
|
- 1.7.1.8 Add Enumerable#map_with_index
|
190
207
|
- 1.7.1.6 Add ActiveRecord::SaveExtensions#save_false_then_reload!
|
data/lib/webget_ruby_ramp.rb
CHANGED
@@ -93,7 +93,7 @@ Testing:
|
|
93
93
|
|
94
94
|
== Integer
|
95
95
|
|
96
|
-
* maps: syntactic sugar to yield n times to a block, returning an array of any results
|
96
|
+
* maps: syntactic sugar to yield n times to a block, returning an array of any results
|
97
97
|
* odd?: is the number odd?
|
98
98
|
|
99
99
|
|
@@ -124,7 +124,6 @@ Testing:
|
|
124
124
|
|
125
125
|
* if: returns 0 if the passed flag is any of: nil, false, 0, [], {} and otherwise returns self
|
126
126
|
* unless: returns 0 unless the passed flag is any of: nil, false, 0, [], {} and otherwise returns self
|
127
|
-
* peta, tera, giga, mega, kilo, hecto, deka, deci, centi, milli, micro, nano: multiply/divide by powers of ten
|
128
127
|
|
129
128
|
|
130
129
|
== Object
|
@@ -199,6 +198,7 @@ Extensions that help debug Ruby programs.
|
|
199
198
|
|
200
199
|
== Changes
|
201
200
|
|
201
|
+
- 1.8.2 Refactored Numeric metric names into their own methods
|
202
202
|
- 1.8.0 100% rcov coverage
|
203
203
|
- 1.7.8 Add rcov testing
|
204
204
|
- 1.7.4 Add Class#publicize_methods, Integer#even?, Integer#odd?
|
@@ -14,15 +14,17 @@ class Array
|
|
14
14
|
|
15
15
|
# Concatenate the items into a string by join.
|
16
16
|
#
|
17
|
-
#
|
17
|
+
# @return [String] concatenated string
|
18
|
+
#
|
19
|
+
# @example Typical Array#join with infix
|
18
20
|
# list=['a','b','c']
|
19
21
|
# list.join("*") => "a*b*c"
|
20
22
|
#
|
21
|
-
#
|
23
|
+
# @example Improved join with infix, prefix, suffix
|
22
24
|
# list=['a','b','c']
|
23
25
|
# list.join("*","[","]") => "[a]*[b]*[c]"
|
24
26
|
#
|
25
|
-
#
|
27
|
+
# @example Improved join with just prefix and suffix
|
26
28
|
# list=['a','b','c']
|
27
29
|
# list.join("[","]") => "[a][b][c]"
|
28
30
|
|
@@ -48,9 +50,9 @@ class Array
|
|
48
50
|
end
|
49
51
|
|
50
52
|
|
51
|
-
#
|
53
|
+
# @return [Boolean] true if size > 0
|
52
54
|
#
|
53
|
-
#
|
55
|
+
# @example
|
54
56
|
# [1,2,3].size? => true
|
55
57
|
# [].size? => false
|
56
58
|
|
@@ -61,12 +63,12 @@ class Array
|
|
61
63
|
|
62
64
|
# Move the first item to the last by using Array#shift and Array#push
|
63
65
|
#
|
64
|
-
#
|
66
|
+
# @example
|
65
67
|
# [1,2,3,4].rotate! => [2,3,4,1]
|
66
68
|
# ['a','b','c'].rotate! => ['b','c','a']
|
67
69
|
# [].rotate! => []
|
68
70
|
#
|
69
|
-
#
|
71
|
+
# @return [Array] self
|
70
72
|
|
71
73
|
def rotate!
|
72
74
|
if size>0
|
@@ -76,9 +78,9 @@ class Array
|
|
76
78
|
end
|
77
79
|
|
78
80
|
|
79
|
-
#
|
81
|
+
# @return [Object] a random item from the array
|
80
82
|
#
|
81
|
-
#
|
83
|
+
# @example
|
82
84
|
# [1,2,3,4].choice => 2
|
83
85
|
# [1,2,3,4].choice => 4
|
84
86
|
# [1,2,3,4].choice => 3
|
@@ -90,9 +92,9 @@ class Array
|
|
90
92
|
end
|
91
93
|
|
92
94
|
|
93
|
-
#
|
95
|
+
# @return [Array] a new array filled with _count_ calls to choice
|
94
96
|
#
|
95
|
-
#
|
97
|
+
# @example
|
96
98
|
# [1,2,3,4].choices(2) => [3,1]
|
97
99
|
# [1,2,3,4].choices(3) => [4,2,3]
|
98
100
|
|
@@ -103,10 +105,10 @@ class Array
|
|
103
105
|
end
|
104
106
|
|
105
107
|
|
106
|
-
#
|
107
|
-
#
|
108
|
+
# @return [Hash] a hash of this array's items as keys,
|
109
|
+
# mapped onto another array's items as values.
|
108
110
|
#
|
109
|
-
#
|
111
|
+
# @example
|
110
112
|
# foo=[:a,:b,:c]
|
111
113
|
# goo=[:x,:y,:z]
|
112
114
|
# foo.onto(goo) => {:a=>:x, :b=>:y, :c=>:z}
|
@@ -126,15 +128,17 @@ class Array
|
|
126
128
|
##############################################################
|
127
129
|
|
128
130
|
|
129
|
-
#
|
131
|
+
# Slice the array.
|
132
|
+
#
|
133
|
+
# @return [Array<Array<Object>>] items in groups of _n_ items (aka slices)
|
130
134
|
#
|
131
|
-
#
|
135
|
+
# @example
|
132
136
|
# [1,2,3,4,5,6,7,8].slices(2) => [[1,2],[3,4],[5,6],[7,8]]
|
133
137
|
# [1,2,3,4,5,6,7,8].slices(4) => [[1,2,3,4],[5,6,7,8]]
|
134
138
|
#
|
135
139
|
# If the slices don't divide evenly, then the last is smaller.
|
136
140
|
#
|
137
|
-
#
|
141
|
+
# @example
|
138
142
|
# [1,2,3,4,5,6,7,8].slices(3) => [[1,2,3],[4,5,6],[7,8]]
|
139
143
|
# [1,2,3,4,5,6,7,8].slices(5) => [[1,2,3,4,5],[6,7,8]]
|
140
144
|
|
@@ -153,12 +157,14 @@ class Array
|
|
153
157
|
|
154
158
|
# Divvy the array, like a pie, into _n_ number of slices.
|
155
159
|
#
|
160
|
+
# @return [Array<Array<Object>>] items grouped into _n_ slices
|
161
|
+
#
|
156
162
|
# If the array divides evenly, then each slice has size/n items.
|
157
163
|
#
|
158
164
|
# Otherwise, divvy makes a best attempt by rounding up to give
|
159
165
|
# earlier slices one more item, which makes the last slice smaller:
|
160
166
|
#
|
161
|
-
#
|
167
|
+
# @example
|
162
168
|
# [1,2,3,4,5].divvy(2) => [[1,2,3],[4,5]]
|
163
169
|
# [1,2,3,4,5,6,7].divvy(3) => [[1,2,3],[4,5,6],[7]]
|
164
170
|
#
|
@@ -166,7 +172,7 @@ class Array
|
|
166
172
|
# no mathematical way to _n_ slices, then divvy will return
|
167
173
|
# as many slices as it can.
|
168
174
|
#
|
169
|
-
#
|
175
|
+
# @example
|
170
176
|
# [1,2,3,4,5,6].divvy(4) => [[1,2],[3,4],[5,6]]
|
171
177
|
|
172
178
|
def divvy(number_of_slices)
|
@@ -183,18 +189,19 @@ class Array
|
|
183
189
|
##############################################################
|
184
190
|
|
185
191
|
|
186
|
-
#
|
192
|
+
# @return [Array] the union of the array's items.
|
193
|
+
#
|
187
194
|
# In typical use, each item is an array.
|
188
195
|
#
|
189
|
-
#
|
196
|
+
# @example using Ruby Array pipe
|
190
197
|
# arr=[[1,2,3,4],[3,4,5,6]]
|
191
198
|
# arr.union => [1,2,3,4,5,6]
|
192
199
|
#
|
193
|
-
#
|
200
|
+
# @example with proc
|
194
201
|
# arr.map(&:foo).union
|
195
202
|
# => foos that are in any of the array items
|
196
203
|
#
|
197
|
-
#
|
204
|
+
# @example with nil
|
198
205
|
# [].union => []
|
199
206
|
|
200
207
|
def union
|
@@ -202,19 +209,20 @@ class Array
|
|
202
209
|
end
|
203
210
|
|
204
211
|
|
205
|
-
#
|
212
|
+
# @return [Array] the intersection of the array's items.
|
213
|
+
#
|
206
214
|
# In typical usage, each item is an array.
|
207
215
|
#
|
208
|
-
#
|
216
|
+
# @example
|
209
217
|
# arr=[[1,2,3,4],[3,4,5,6]]
|
210
218
|
# arr.intersect
|
211
219
|
# => [3,4]
|
212
220
|
#
|
213
|
-
#
|
221
|
+
# @example with proc
|
214
222
|
# arr.map(&:foo).intersect
|
215
223
|
# => foos that are in all of the array items
|
216
224
|
#
|
217
|
-
#
|
225
|
+
# @example with nil
|
218
226
|
# [].intersect => []
|
219
227
|
|
220
228
|
def intersect
|
@@ -229,14 +237,14 @@ class Array
|
|
229
237
|
#
|
230
238
|
##############################################################
|
231
239
|
|
232
|
-
#
|
240
|
+
# @return [Array] the rest of the items of self, after a shift.
|
233
241
|
#
|
234
|
-
#
|
242
|
+
# @example
|
235
243
|
# list=['a','b','c']
|
236
244
|
# list.shift => 'a'
|
237
245
|
# list.shifted => ['b','c']
|
238
246
|
#
|
239
|
-
#
|
247
|
+
# @example with length
|
240
248
|
# list.shifted(0) => ['a','b','c']
|
241
249
|
# list.shifted(1) => ['b','c']
|
242
250
|
# list.shifted(2) => ['c']
|
@@ -262,14 +270,16 @@ class Array
|
|
262
270
|
alias :rest :shifted
|
263
271
|
|
264
272
|
|
265
|
-
# Delete the first _number_of_items_ items.
|
273
|
+
# Delete the first _number_of_items_ items.
|
274
|
+
#
|
275
|
+
# @return [Array] the array, minus the deleted items.
|
266
276
|
#
|
267
|
-
#
|
277
|
+
# @example
|
268
278
|
# list=['a','b','c']
|
269
279
|
# list.shifted!
|
270
280
|
# list => ['b','c']
|
271
281
|
#
|
272
|
-
#
|
282
|
+
# @example with length:
|
273
283
|
# list=['a','b','c']
|
274
284
|
# list.shifted!(2)
|
275
285
|
# list => ['c']
|
@@ -289,10 +299,12 @@ class Array
|
|
289
299
|
|
290
300
|
# Randomly arrange the array items.
|
291
301
|
#
|
302
|
+
# @return [Array] the array, with its items shuffled.
|
303
|
+
#
|
292
304
|
# This implementation is optimized for speed, not for memory use.
|
293
305
|
# See http://codeidol.com/other/rubyckbk/Arrays/Shuffling-an-Array/
|
294
306
|
#
|
295
|
-
#
|
307
|
+
# @example
|
296
308
|
# list=
|
297
309
|
# list=['a','b','c']
|
298
310
|
# list.shuffle!
|
@@ -305,12 +317,13 @@ class Array
|
|
305
317
|
end
|
306
318
|
end
|
307
319
|
|
308
|
-
|
320
|
+
|
321
|
+
# @return [Array] a new array with the items shuffled.
|
309
322
|
#
|
310
323
|
# This implementation is optimized for speed, not for memory use.
|
311
324
|
# See http://codeidol.com/other/rubyckbk/Arrays/Shuffling-an-Array/
|
312
325
|
#
|
313
|
-
#
|
326
|
+
# @example
|
314
327
|
# list=
|
315
328
|
# list=['a','b','c']
|
316
329
|
# list.shuffle!
|
@@ -327,17 +340,17 @@ class Array
|
|
327
340
|
#
|
328
341
|
##############################################################
|
329
342
|
|
330
|
-
#
|
343
|
+
# @return [String] a CSV (Comma Separated Value) string of this array.
|
331
344
|
#
|
332
|
-
#
|
345
|
+
# @example of a one-dimensional array
|
333
346
|
#
|
334
347
|
# [1,2,3].to_csv => "1,2,3\n"
|
335
348
|
#
|
336
|
-
#
|
349
|
+
# @example of a multi-dimensional array
|
337
350
|
#
|
338
351
|
# [[1,2,3],[4,5,6]] => "1,2,3\n4,5,6\n"
|
339
352
|
#
|
340
|
-
#
|
353
|
+
# @example of a blank array
|
341
354
|
#
|
342
355
|
# [].to_csv => ""
|
343
356
|
#
|
@@ -366,12 +379,12 @@ class Array
|
|
366
379
|
end
|
367
380
|
|
368
381
|
|
369
|
-
#
|
370
|
-
#
|
382
|
+
# @return [String] a TSV (Tab Separated Value) string
|
383
|
+
# representation of a multi-dimensional array.
|
371
384
|
#
|
372
385
|
# Each subarray becomes one 'line' in the output.
|
373
386
|
#
|
374
|
-
#
|
387
|
+
# @example of a blank array
|
375
388
|
#
|
376
389
|
# [].to_csv => ""
|
377
390
|
|
@@ -12,10 +12,12 @@ class Class
|
|
12
12
|
#
|
13
13
|
# From http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
|
14
14
|
#
|
15
|
-
#
|
15
|
+
# @example
|
16
16
|
# MyClass.publicize_methods do
|
17
17
|
# ...call some method that was private or protected...
|
18
18
|
# end
|
19
|
+
#
|
20
|
+
# @return void
|
19
21
|
|
20
22
|
def publicize_methods
|
21
23
|
saved_private_instance_methods = self.private_instance_methods
|
data/lib/webget_ruby_ramp/csv.rb
CHANGED
@@ -4,16 +4,16 @@
|
|
4
4
|
|
5
5
|
class CSV
|
6
6
|
|
7
|
-
#
|
7
|
+
# @return [Hash<String,String>] HTTP headers for a typical CSV file download without caching.
|
8
8
|
#
|
9
9
|
# ==Options
|
10
10
|
# - filename: defaults to "data.csv"
|
11
11
|
# - request: the incoming http request, which is used to return MSIE-specific headers
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# @example
|
14
14
|
# headers = CSV.http_headers("myfile.csv")
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# @example for Rails
|
17
17
|
# response.headers.merge CSV.http_headers("myfile.csv")
|
18
18
|
#
|
19
19
|
# Ideas from http://stackoverflow.com/questions/94502/in-rails-how-to-return-records-as-a-csv-file/94520
|
@@ -42,7 +42,7 @@ class CSV
|
|
42
42
|
# Rails automatically defines a _request_ object,
|
43
43
|
# that has an env HTTP_USER_AGENT.
|
44
44
|
#
|
45
|
-
# @return [Hash]
|
45
|
+
# @return [Hash<String,String>] HTTP headers
|
46
46
|
|
47
47
|
def self.http_headers_adjust_for_broken_msie(options={})
|
48
48
|
request = options[:request] || request
|
@@ -6,9 +6,9 @@ require 'date'
|
|
6
6
|
|
7
7
|
class Date
|
8
8
|
|
9
|
-
#
|
9
|
+
# @return [Boolean] true if the date is a weekday: Mon, Tue, Wed, Thu, Fri
|
10
10
|
#
|
11
|
-
#
|
11
|
+
# @example
|
12
12
|
# d = Date.parse('2008-01-01')
|
13
13
|
# d.wday => 2
|
14
14
|
# d.weekday? => true
|
@@ -18,9 +18,9 @@ class Date
|
|
18
18
|
end
|
19
19
|
|
20
20
|
|
21
|
-
#
|
21
|
+
# @return [Boolean] true if the date is a weekend: Sat, Sun
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# @example
|
24
24
|
# d = Date.parse('2008-01-05')
|
25
25
|
# d.wday => 6
|
26
26
|
# d.weekend? => true
|
@@ -30,9 +30,9 @@ class Date
|
|
30
30
|
end
|
31
31
|
|
32
32
|
|
33
|
-
#
|
33
|
+
# @return [Date] a random date between min & max
|
34
34
|
#
|
35
|
-
#
|
35
|
+
# @example
|
36
36
|
# d1= Date.parse('2008-01-01')
|
37
37
|
# d2= Date.parse('2009-01-01')
|
38
38
|
# Date.between(d1,d3) => Date 2008-11-22
|
@@ -42,9 +42,9 @@ class Date
|
|
42
42
|
end
|
43
43
|
|
44
44
|
|
45
|
-
#
|
45
|
+
# @return [String] date in a sql format: YYYY-MM-DD
|
46
46
|
#
|
47
|
-
#
|
47
|
+
# @example
|
48
48
|
# d=Date.today
|
49
49
|
# d.to_sql => "2007-12-31"
|
50
50
|
|
@@ -53,14 +53,14 @@ class Date
|
|
53
53
|
end
|
54
54
|
|
55
55
|
|
56
|
-
#
|
56
|
+
# @return [Integer] the age in years for a given date.
|
57
57
|
#
|
58
|
-
#
|
58
|
+
# @example
|
59
59
|
#
|
60
60
|
# birthdate=Date.new(1980,10,31)
|
61
61
|
# birthdate.age_years => 28 (where 28 is the correct age for today)
|
62
62
|
#
|
63
|
-
#
|
63
|
+
# @example of custom dates
|
64
64
|
#
|
65
65
|
# birthdate=Date.new(1980,10,31)
|
66
66
|
#
|
@@ -82,7 +82,7 @@ class Date
|
|
82
82
|
end
|
83
83
|
|
84
84
|
|
85
|
-
#
|
85
|
+
# @return [Integer] the age in days for a given date.
|
86
86
|
|
87
87
|
def age_days(compare_date=Date.today)
|
88
88
|
(compare_date.is_a? Date) or raise ArgumentError, "compare_date must be a date"
|