sixarm_ruby_ramp 4.2.3 → 4.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Rakefile +3 -2
- data/lib/sixarm_ruby_ramp/array/join.rb +2 -0
- data/lib/sixarm_ruby_ramp/enumerable/each.rb +149 -0
- data/lib/sixarm_ruby_ramp/integer/rbit.rb +2 -0
- data/lib/sixarm_ruby_ramp/integer.rb +7 -4
- data/lib/sixarm_ruby_ramp/string.rb +1 -1
- data/lib/sixarm_ruby_ramp.rb +1 -1
- data/test/sixarm_ruby_ramp_test/array/join_test.rb +1 -1
- data/test/sixarm_ruby_ramp_test/array/shuffle_test.rb +1 -1
- data/test/sixarm_ruby_ramp_test/array_test.rb +2 -3
- data/test/sixarm_ruby_ramp_test/class_test.rb +2 -4
- data/test/sixarm_ruby_ramp_test/csv_test.rb +3 -5
- data/test/sixarm_ruby_ramp_test/date_test.rb +13 -15
- data/test/sixarm_ruby_ramp_test/enumerable/each_test.rb +337 -0
- data/test/sixarm_ruby_ramp_test/enumerable/map_test.rb +1 -1
- data/test/sixarm_ruby_ramp_test/enumerable/nitems_test.rb +1 -1
- data/test/sixarm_ruby_ramp_test/enumerable/select_test.rb +1 -1
- data/test/sixarm_ruby_ramp_test/enumerable_test.rb +2 -4
- data/test/sixarm_ruby_ramp_test/file_test.rb +4 -6
- data/test/sixarm_ruby_ramp_test/fixnum_test.rb +2 -4
- data/test/sixarm_ruby_ramp_test/hash_test.rb +2 -2
- data/test/sixarm_ruby_ramp_test/integer/rbit_test.rb +1 -1
- data/test/sixarm_ruby_ramp_test/integer_test.rb +4 -5
- data/test/sixarm_ruby_ramp_test/io_test.rb +2 -3
- data/test/sixarm_ruby_ramp_test/kernel_test.rb +5 -6
- data/test/sixarm_ruby_ramp_test/math_test.rb +2 -3
- data/test/sixarm_ruby_ramp_test/nil_test.rb +2 -3
- data/test/sixarm_ruby_ramp_test/numeric_test.rb +2 -2
- data/test/sixarm_ruby_ramp_test/object_test.rb +2 -3
- data/test/sixarm_ruby_ramp_test/pairable_test.rb +2 -2
- data/test/sixarm_ruby_ramp_test/process_test.rb +2 -2
- data/test/sixarm_ruby_ramp_test/string_test.rb +2 -27
- data/test/sixarm_ruby_ramp_test/symbol_test.rb +2 -16
- data/test/sixarm_ruby_ramp_test/time_test.rb +3 -4
- data/test/sixarm_ruby_ramp_test/yaml_test.rb +2 -6
- data/test/sixarm_ruby_ramp_test.rb +5 -33
- data.tar.gz.sig +0 -0
- metadata +85 -11
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
- data/CHANGES.md +0 -24
- data/CONTRIBUTING.md +0 -28
- data/LICENSE.md +0 -28
- data/README.md +0 -249
- data/VERSION +0 -1
- data/lib/sixarm_ruby_ramp/xml.rb +0 -0
- data/test/sixarm_ruby_ramp_test/xml_test.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd28e48ca54cace863d1df36f8db7bfdd6c617af
|
4
|
+
data.tar.gz: 5c2a913207a9b83f7da75c8910c5f44b876017a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21a8671ccf5d9fe673d8f9da26a2370ec2f4d1c8d1720efaea5b167213b65088bf2b353d2566ea5dc387a3432b9262d90907f32c547183856fb0400e57548633
|
7
|
+
data.tar.gz: cdb4647686ddb9417adcffc32c96481033650b5d30a2668ae8609221ad9fbddbf2f27c7949e6e2b09517f91a75305e0c3fe3412c80d613b263a0a42849ad72f1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Rakefile
CHANGED
@@ -0,0 +1,149 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Enumerable
|
3
|
+
|
4
|
+
# Get each element at a given index or indices.
|
5
|
+
#
|
6
|
+
# Example: use an index.
|
7
|
+
#
|
8
|
+
# ["a", "b", "c", "d", "e"].each_at(1)
|
9
|
+
# #=> "b"
|
10
|
+
#
|
11
|
+
# Example: use an index that is negative when size is known.
|
12
|
+
#
|
13
|
+
# ["a", "b", "c", "d", "e"].each_at(-1)
|
14
|
+
# => "e"
|
15
|
+
#
|
16
|
+
# Example: use a range.
|
17
|
+
#
|
18
|
+
# ["a", "b", "c", "d", "e"].each_at(1..3)
|
19
|
+
# => "b", "c", "d"
|
20
|
+
#
|
21
|
+
# Example: use a range that has negatives when size is known.
|
22
|
+
#
|
23
|
+
# ["a", "b", "c", "d", "e"].each_at(-3..-1)
|
24
|
+
# => "c", "d", "e"
|
25
|
+
#
|
26
|
+
# Example: use any object that responds to #each or #include?.
|
27
|
+
#
|
28
|
+
# ["a", "b", "c", "d", "e"].each_at([4, 2, -2])
|
29
|
+
# => "e", "c", "d"
|
30
|
+
#
|
31
|
+
def each_at(filter)
|
32
|
+
filter, optimize_for_whole_numbers = each_at_normalize_filter(filter)
|
33
|
+
|
34
|
+
# Handle variations.
|
35
|
+
#
|
36
|
+
# Can we call self#at?
|
37
|
+
#
|
38
|
+
# * Yes: look up a self element by index.
|
39
|
+
# * No: iterate on self, comparing the loop count to filter target.
|
40
|
+
#
|
41
|
+
# Can we call filter#each?
|
42
|
+
#
|
43
|
+
# * Yes: iterate on the filter elements.
|
44
|
+
# * No: iterate on self, comparing the loop count to filter#include?
|
45
|
+
#
|
46
|
+
# Can we optimize for whole numbers?
|
47
|
+
#
|
48
|
+
# * Yes: we know that all filter targets are whole numbers.
|
49
|
+
# * No: we must convert the filter target to an index size each time.
|
50
|
+
#
|
51
|
+
if self.respond_to?(:at) && filter.respond_to?(:each)
|
52
|
+
if optimize_for_whole_numbers
|
53
|
+
# each_at_strategy_with_self_at_and_filter_each_and_whole_numbers(filter)
|
54
|
+
filter.each{|i|
|
55
|
+
yield(at(i))
|
56
|
+
}
|
57
|
+
else
|
58
|
+
# each_at_strategy_with_self_at_and_filter_each(filter)
|
59
|
+
filter.each{|i|
|
60
|
+
yield(at(i >= 0 ? i : i + self.size))
|
61
|
+
}
|
62
|
+
end
|
63
|
+
elsif filter.respond_to?(:include?)
|
64
|
+
# each_at_strategy_with_count(filter)
|
65
|
+
i = 0
|
66
|
+
s = respond_to?(:size) ? size : nil
|
67
|
+
each{|e|
|
68
|
+
yield(e) if (filter.include?(i) || (size && filter.include(i - size)))
|
69
|
+
i += 1
|
70
|
+
}
|
71
|
+
else
|
72
|
+
raise ArgumentError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Implement #each_at by using a strategy with no optimization.
|
77
|
+
#
|
78
|
+
# When #each_at tests that either self#at is unavailable or filter#each
|
79
|
+
# is unavailable, then #each_at calls this strategy.
|
80
|
+
#
|
81
|
+
# This strategy uses a loop counter and iteration on the self elements,
|
82
|
+
# and each iteration, test whether the counter is in the filter.
|
83
|
+
#
|
84
|
+
# This strategy is the slowest, and for the worst-case need.
|
85
|
+
# This strategy is rarely needed in the wild.
|
86
|
+
#
|
87
|
+
def each_at_strategy_with_optimization_off(filter)
|
88
|
+
i = 0
|
89
|
+
if respond_to?(:size)
|
90
|
+
each{|e|
|
91
|
+
yield(e) if (filter.include?(i) || (size && filter.include?(i - size)))
|
92
|
+
i += 1
|
93
|
+
}
|
94
|
+
else
|
95
|
+
each{|e|
|
96
|
+
yield(e) if (filter.include?(i))
|
97
|
+
i += 1
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Implement #each_at by using a strategy with some optimization.
|
103
|
+
#
|
104
|
+
# When #each_at tests that both self#at is available and filter#each
|
105
|
+
# is available, yet cannot test that all indexes are whole numbers,
|
106
|
+
# then #each_at calls this strategy.
|
107
|
+
#
|
108
|
+
def each_at_strategy_with_optimization_min(filter)
|
109
|
+
filter.each{|i|
|
110
|
+
yield(at(i >= 0 ? i : i + self.size))
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
# Implement #each_at by using a strategy with full optimization.
|
115
|
+
#
|
116
|
+
# When #each_at tests that both self#at is available and filter#each
|
117
|
+
# is available, and can test that all indexes are whole numbers,
|
118
|
+
# then #each_at calls this strategy.
|
119
|
+
#
|
120
|
+
def each_at_strategy_with_optimization_max(filter)
|
121
|
+
filter.each{|i|
|
122
|
+
yield(at(i))
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
# Normalize the filter to make it respond to #each and #include?.
|
127
|
+
#
|
128
|
+
# If we can guarantee the filter is all whole numbers,
|
129
|
+
# then subsequent method calls can optimize the index lookup,
|
130
|
+
# by looking for the whole numbers instead of negative numbers.
|
131
|
+
#
|
132
|
+
def each_at_normalize_filter(filter)
|
133
|
+
case filter
|
134
|
+
when Numeric
|
135
|
+
return [filter.to_i], filter >= 0
|
136
|
+
when Range
|
137
|
+
if filter.first < 0 || filter.last < 0
|
138
|
+
min = filter.first.to_i; min += size if min < 0
|
139
|
+
max = filter.last.to_i; max += size if max < 0
|
140
|
+
max -= 1 if filter.exclude_end?
|
141
|
+
filter = min..max
|
142
|
+
end
|
143
|
+
return filter, true
|
144
|
+
else
|
145
|
+
return filter, false
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -6,21 +6,24 @@ class Integer
|
|
6
6
|
|
7
7
|
# Syntactic sugar to yield n times to a block.
|
8
8
|
#
|
9
|
-
# Comparison to Integer#times
|
9
|
+
# ## Comparison to Integer#times
|
10
|
+
#
|
10
11
|
# Integer#maps is similar to Integer#times except that the output from each
|
11
12
|
# call to the block is captured in an array element and that array is
|
12
13
|
# returned to the calling code.
|
13
14
|
#
|
14
|
-
# @return an array of
|
15
|
+
# @return an array of results
|
15
16
|
#
|
16
17
|
# @example Generate an array of three random numbers
|
17
18
|
# 3.maps{rand}
|
18
19
|
# => [0.0248131784304143, 0.814666170190905, 0.15812816258206]
|
19
20
|
#
|
20
|
-
|
21
|
+
# @example Multiply the current index
|
22
|
+
# 3.maps{|i| i * 2}
|
23
|
+
# => [0, 2, 4]
|
24
|
+
#
|
21
25
|
def maps
|
22
26
|
return (0...self).map{|item| yield item}
|
23
27
|
end
|
24
28
|
|
25
|
-
|
26
29
|
end
|
@@ -221,7 +221,7 @@ class String
|
|
221
221
|
# This method defaults to length = self.lorem_length.
|
222
222
|
|
223
223
|
def self.lorem(length=self.lorem_length)
|
224
|
-
['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'].
|
224
|
+
['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'].sample(length).join
|
225
225
|
end
|
226
226
|
|
227
227
|
|
data/lib/sixarm_ruby_ramp.rb
CHANGED
@@ -11,6 +11,7 @@ Please see README
|
|
11
11
|
'csv',
|
12
12
|
'date',
|
13
13
|
'enumerable',
|
14
|
+
'enumerable/each',
|
14
15
|
'enumerable/map',
|
15
16
|
'enumerable/nitems',
|
16
17
|
'enumerable/select',
|
@@ -30,7 +31,6 @@ Please see README
|
|
30
31
|
'string',
|
31
32
|
'symbol',
|
32
33
|
'time',
|
33
|
-
'xml',
|
34
34
|
'yaml'
|
35
35
|
].map{|x|
|
36
36
|
require File.dirname(__FILE__) + "/sixarm_ruby_ramp/#{x}.rb"
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require "
|
3
|
-
require "sixarm_ruby_ramp"
|
4
|
-
|
2
|
+
require "sixarm_ruby_ramp_test"
|
3
|
+
require "sixarm_ruby_ramp/class"
|
5
4
|
|
6
5
|
class ClassTest < Minitest::Test
|
7
6
|
|
8
|
-
|
9
7
|
METHOD_REGEXP = /^[abc]\W*$/
|
10
8
|
def test_publicize_methods
|
11
9
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require "
|
3
|
-
require "sixarm_ruby_ramp"
|
4
|
-
|
2
|
+
require "sixarm_ruby_ramp_test"
|
3
|
+
require "sixarm_ruby_ramp/csv"
|
5
4
|
|
6
5
|
class CSVTest < Minitest::Test
|
7
6
|
|
@@ -42,6 +41,5 @@ class MockRequest
|
|
42
41
|
def env
|
43
42
|
@env
|
44
43
|
end
|
45
|
-
|
44
|
+
|
46
45
|
end
|
47
|
-
|
@@ -1,14 +1,13 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require "
|
3
|
-
require "sixarm_ruby_ramp"
|
4
|
-
|
2
|
+
require "sixarm_ruby_ramp_test"
|
3
|
+
require "sixarm_ruby_ramp/date"
|
5
4
|
|
6
5
|
class DateTest < Minitest::Test
|
7
6
|
|
8
7
|
|
9
8
|
def test_weekday
|
10
9
|
# Start on Monday, January 1, 2007
|
11
|
-
assert( Date.new(2007,1,1).weekday?)
|
10
|
+
assert( Date.new(2007,1,1).weekday?)
|
12
11
|
assert( Date.new(2007,1,2).weekday?)
|
13
12
|
assert( Date.new(2007,1,3).weekday?)
|
14
13
|
assert( Date.new(2007,1,4).weekday?)
|
@@ -21,14 +20,14 @@ class DateTest < Minitest::Test
|
|
21
20
|
|
22
21
|
def test_weekend
|
23
22
|
# Start on Monday, January 1, 2007
|
24
|
-
assert(!Date.new(2007,1,1).weekend?)
|
25
|
-
assert(!Date.new(2007,1,2).weekend?)
|
26
|
-
assert(!Date.new(2007,1,3).weekend?)
|
27
|
-
assert(!Date.new(2007,1,4).weekend?)
|
28
|
-
assert(!Date.new(2007,1,5).weekend?)
|
29
|
-
assert( Date.new(2007,1,6).weekend?)
|
30
|
-
assert( Date.new(2007,1,7).weekend?)
|
31
|
-
assert(!Date.new(2007,1,8).weekend?)
|
23
|
+
assert(!Date.new(2007,1,1).weekend?)
|
24
|
+
assert(!Date.new(2007,1,2).weekend?)
|
25
|
+
assert(!Date.new(2007,1,3).weekend?)
|
26
|
+
assert(!Date.new(2007,1,4).weekend?)
|
27
|
+
assert(!Date.new(2007,1,5).weekend?)
|
28
|
+
assert( Date.new(2007,1,6).weekend?)
|
29
|
+
assert( Date.new(2007,1,7).weekend?)
|
30
|
+
assert(!Date.new(2007,1,8).weekend?)
|
32
31
|
end
|
33
32
|
|
34
33
|
|
@@ -43,8 +42,8 @@ class DateTest < Minitest::Test
|
|
43
42
|
|
44
43
|
|
45
44
|
def test_between
|
46
|
-
d1= Date.parse('2008-01-01')
|
47
|
-
d2= Date.parse('2009-01-01')
|
45
|
+
d1= Date.parse('2008-01-01')
|
46
|
+
d2= Date.parse('2009-01-01')
|
48
47
|
d3= Date.between(d1,d2)
|
49
48
|
assert(d3>=d1)
|
50
49
|
assert(d3<=d2)
|
@@ -57,4 +56,3 @@ class DateTest < Minitest::Test
|
|
57
56
|
|
58
57
|
|
59
58
|
end
|
60
|
-
|