webget_ruby_ramp 1.8.0 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- 0��壳>m%ka eB��_���E���o���LjPV���n�pZae/����������� ���}��9G��H����AI�4(M�*ʆ�/"I��$��Y�9
2
- Y(��O o!Y�&�͒Vijv�
1
+ �]x̸4�B^���xf!�8�B��?�_��YӌJł� ��if]>$���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
- * Each has an associated test class, e.g., ArrayTest, DateTest, etc.
13
- * The easy way to run the tests: gem install webget_ruby_ramp --test
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 (e.g. 3.maps{rand} => [0.4351325,0.7778625,0.158613534])
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
- * method_name:
94
- * method_name_of_caller: returns the name of the method which called the current method, or the Nth parent up the call stack if the optional caller_index parameter is passed.
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.7.3 Refactor Rails classes to their own gem
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!
@@ -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 (e.g. 3.maps{rand} => [0.4351325,0.7778625,0.158613534])
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
- # ==Typical Array#join with infix
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
- # ==Improved join with infix, prefix, suffix
23
+ # @example Improved join with infix, prefix, suffix
22
24
  # list=['a','b','c']
23
25
  # list.join("*","[","]") => "[a]*[b]*[c]"
24
26
  #
25
- # ==Improved join with just prefix and suffix
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
- # Return true if size > 0
53
+ # @return [Boolean] true if size > 0
52
54
  #
53
- # ==Examples
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
- # ==Examples
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
- # Return self
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
- # Return a random item from the array
81
+ # @return [Object] a random item from the array
80
82
  #
81
- # ==Examples
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
- # Return a new array filled with _count_ calls to choice
95
+ # @return [Array] a new array filled with _count_ calls to choice
94
96
  #
95
- # ==Examples
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
- # Return a hash of this array's items as keys
107
- # mapped onto another array's items as values.
108
+ # @return [Hash] a hash of this array's items as keys,
109
+ # mapped onto another array's items as values.
108
110
  #
109
- # ==Example
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
- # Return items in groups of _n_ items (aka slices)
131
+ # Slice the array.
132
+ #
133
+ # @return [Array<Array<Object>>] items in groups of _n_ items (aka slices)
130
134
  #
131
- # ==Examples
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
- # ==Examples
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
- # ==Examples
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
- # ==Examples
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
- # Return the union of the array's items.
192
+ # @return [Array] the union of the array's items.
193
+ #
187
194
  # In typical use, each item is an array.
188
195
  #
189
- # ==Example using Ruby Array pipe
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
- # ==Examples with proc
200
+ # @example with proc
194
201
  # arr.map(&:foo).union
195
202
  # => foos that are in any of the array items
196
203
  #
197
- # ==Example with nil
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
- # Return the intersection of the array's items.
212
+ # @return [Array] the intersection of the array's items.
213
+ #
206
214
  # In typical usage, each item is an array.
207
215
  #
208
- # ==Examples
216
+ # @example
209
217
  # arr=[[1,2,3,4],[3,4,5,6]]
210
218
  # arr.intersect
211
219
  # => [3,4]
212
220
  #
213
- # ==Examples with proc
221
+ # @example with proc
214
222
  # arr.map(&:foo).intersect
215
223
  # => foos that are in all of the array items
216
224
  #
217
- # ==Example with nil
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
- # Returns the rest of the items of self, after a shift.
240
+ # @return [Array] the rest of the items of self, after a shift.
233
241
  #
234
- # ==Example
242
+ # @example
235
243
  # list=['a','b','c']
236
244
  # list.shift => 'a'
237
245
  # list.shifted => ['b','c']
238
246
  #
239
- # ==Example with length
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. Returns the array, not the deleted items.
273
+ # Delete the first _number_of_items_ items.
274
+ #
275
+ # @return [Array] the array, minus the deleted items.
266
276
  #
267
- # ==Example
277
+ # @example
268
278
  # list=['a','b','c']
269
279
  # list.shifted!
270
280
  # list => ['b','c']
271
281
  #
272
- # ==Example with length:
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
- # ==Example
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
- # Return the array items in random order.
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
- # ==Example
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
- # Returns a CSV (Comma Separated Value) string of this array.
343
+ # @return [String] a CSV (Comma Separated Value) string of this array.
331
344
  #
332
- # ==Example of a one-dimensional array
345
+ # @example of a one-dimensional array
333
346
  #
334
347
  # [1,2,3].to_csv => "1,2,3\n"
335
348
  #
336
- # ==Example of a multi-dimensional array
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
- # ==Example of a blank array
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
- # Returns a TSV (Tab Separated Value) string
370
- # representation of a multi-dimensional array.
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
- # ==Example of a blank array
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
- # ==Example
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
@@ -4,16 +4,16 @@
4
4
 
5
5
  class CSV
6
6
 
7
- # Return HTTP headers for a typical CSV file download without caching.
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
- # ==Example
13
+ # @example
14
14
  # headers = CSV.http_headers("myfile.csv")
15
15
  #
16
- # ==Example for Rails
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] options
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
- # Return true if the date is a weekday: Mon, Tue, Wed, Thu, Fri
9
+ # @return [Boolean] true if the date is a weekday: Mon, Tue, Wed, Thu, Fri
10
10
  #
11
- # ==Example
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
- # Return true if the date is a weekend: Sat, Sun
21
+ # @return [Boolean] true if the date is a weekend: Sat, Sun
22
22
  #
23
- # ==Example
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
- # Return a random date between min & max
33
+ # @return [Date] a random date between min & max
34
34
  #
35
- # ==Example
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
- # Return date in a sql format: YYYY-MM-DD
45
+ # @return [String] date in a sql format: YYYY-MM-DD
46
46
  #
47
- # ==Example
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
- # Return the age in years for a given date.
56
+ # @return [Integer] the age in years for a given date.
57
57
  #
58
- # ==Example
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
- # ==Example of custom dates
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
- # Return the age in days for a given date.
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"