tbpgr_utils 0.0.123 → 0.0.124
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.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/open_classes/array/gte_gte.rb +30 -5
- data/lib/open_classes/string/gte_gte.rb +13 -10
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/open_classes/array/gte_gte_spec.rb +17 -12
- data/spec/open_classes/string/gte_gte_spec.rb +12 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abc47f0e31b15cdf12a627961e0f4c286731db50
|
4
|
+
data.tar.gz: c96f77f49a40f07e6aabf03644ac57235bcbd60a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6275aa412ed95ff54536aa8510ccf3652206b2f731e077f66a364d4835e0a006502194122138c266b733a0e161f0bd9f1de7b4ca0bbc1adb5581c8bf2c54e9
|
7
|
+
data.tar.gz: 5a516285c429da9a5d9e1a81f942cc9b496f3525724fe2c067aae9b765d7e490e4de728f1c9d1f921772b3f92f16400c117064bce92fafa01bf45d40273eb73e
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
### List
|
25
25
|
| class/module/method | mean |
|
26
26
|
|:----------- |:------------ |
|
27
|
-
|[TbpgrUtils Array#>>](#array) |
|
27
|
+
|[TbpgrUtils Array#>>](#array) |return ArrayContext for each execute |
|
28
28
|
|[TbpgrUtils Array#average](#arrayaverage) |return average |
|
29
29
|
|[TbpgrUtils Array#kernel_send](#arraykernel_send) |alias of map {|v|send :some_kernel_method, v} |
|
30
30
|
|[TbpgrUtils Array#sum](#arraysum) |alias of Array#reduce(&:+). |
|
@@ -167,8 +167,8 @@ Or install it yourself as:
|
|
167
167
|
### Array#>>
|
168
168
|
~~~ruby
|
169
169
|
require 'tbpgr_utils'
|
170
|
-
[*'a'..'c']
|
171
|
-
[*'
|
170
|
+
[*'a'..'c'].>>.ord # => [97, 98, 99]
|
171
|
+
[*'aa'..'ac'].>>.gsub("a", "c") # => ['cc', 'cb', 'cc']
|
172
172
|
~~~
|
173
173
|
|
174
174
|
[back to list](#list)
|
@@ -3027,9 +3027,8 @@ print st.tournament # => [[3], [1, 3], [3, 2]]
|
|
3027
3027
|
~~~ruby
|
3028
3028
|
require 'tbpgr_utils'
|
3029
3029
|
|
3030
|
-
"abc"
|
3031
|
-
"abc"
|
3032
|
-
"abc">>-> (x) { (x.ord + 1).chr } # => ["c", "d", "e"]
|
3030
|
+
"abc".>> .next # => 'bcd'
|
3031
|
+
"abc".>> :+, "a" # => 'adbdcd'
|
3033
3032
|
~~~
|
3034
3033
|
|
3035
3034
|
[back to list](#list)
|
@@ -3604,6 +3603,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
3604
3603
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
3605
3604
|
|
3606
3605
|
## History
|
3606
|
+
* version 0.0.124 : change spec of Array#>>, String#>>
|
3607
3607
|
* version 0.0.123 : add String#>>
|
3608
3608
|
* version 0.0.122 : add String#justify_char
|
3609
3609
|
* version 0.0.121 : add Array#average
|
@@ -1,15 +1,40 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
class ArrayContext
|
4
|
+
attr_reader :receiver
|
5
|
+
|
6
|
+
def initialize(receiver)
|
7
|
+
@receiver = receiver
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method_name, *args , &block)
|
11
|
+
if args.size > 0
|
12
|
+
receiver.map do |value|
|
13
|
+
value.send method_name, *args
|
14
|
+
end
|
15
|
+
else
|
16
|
+
receiver.map do |value|
|
17
|
+
value.send method_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_a
|
23
|
+
@receiver
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
3
27
|
# Array
|
4
28
|
class Array
|
5
|
-
#
|
29
|
+
# return ArrayContext for each execute
|
6
30
|
#
|
7
31
|
# === Example
|
8
32
|
#
|
9
|
-
# [*'a'..'c']
|
33
|
+
# [*'a'..'c'].>>.ord # => [97, 98, 99]
|
34
|
+
# [*'a'..'c'].>>.'ord' # => [97, 98, 99]
|
35
|
+
# [*'aa'..'ac'].>>.gsub("a", "c") # => ['cc', 'cb', 'cc']
|
10
36
|
#
|
11
|
-
def >>(
|
12
|
-
|
13
|
-
map(&method_name.to_sym)
|
37
|
+
def >>(dummy = nil)
|
38
|
+
ArrayContext.new(self)
|
14
39
|
end
|
15
40
|
end
|
@@ -1,21 +1,24 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'tbpgr_utils'
|
2
3
|
|
3
4
|
# String
|
4
5
|
class String
|
5
|
-
# self
|
6
|
+
# self convert to Array. execute each elements
|
6
7
|
#
|
7
8
|
# === Example
|
8
9
|
#
|
9
|
-
# "abc"
|
10
|
-
# "abc"
|
11
|
-
# "abc">>-> (x) { (x.ord + 1).chr } # => ["c", "d", "e"]
|
10
|
+
# "abc".>> :next # => 'bcd'
|
11
|
+
# "abc".>> :+, "a" # => 'adbdcd'
|
12
12
|
#
|
13
|
-
def >>(method_name)
|
13
|
+
def >>(method_name, *args)
|
14
14
|
return self unless [Symbol, String, Proc].include? method_name.class
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
array_context = split('').>>
|
16
|
+
rets =
|
17
|
+
if args.size.nil? || args.size == 0
|
18
|
+
array_context.send method_name
|
19
|
+
else
|
20
|
+
array_context.send method_name, *args
|
21
|
+
end
|
22
|
+
rets.join
|
20
23
|
end
|
21
24
|
end
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -7,24 +7,25 @@ describe Array do
|
|
7
7
|
cases = [
|
8
8
|
{
|
9
9
|
case_no: 1,
|
10
|
-
case_title: '
|
10
|
+
case_title: 'no args case',
|
11
11
|
input: [*'a'..'c'],
|
12
12
|
method_name: :ord,
|
13
13
|
expected: [97, 98, 99],
|
14
14
|
},
|
15
15
|
{
|
16
|
-
case_no:
|
17
|
-
case_title: '
|
18
|
-
input: [*'
|
19
|
-
method_name: '
|
20
|
-
|
16
|
+
case_no: 3,
|
17
|
+
case_title: 'have args case',
|
18
|
+
input: [*'aa'..'ac'],
|
19
|
+
method_name: 'gsub',
|
20
|
+
args: ['a', 'c'],
|
21
|
+
expected: ['cc', 'cb', 'cc'],
|
21
22
|
},
|
22
23
|
{
|
23
|
-
case_no:
|
24
|
-
case_title: '
|
25
|
-
input: [*'
|
26
|
-
method_name:
|
27
|
-
expected: [*'
|
24
|
+
case_no: 4,
|
25
|
+
case_title: 'have args case',
|
26
|
+
input: [*'aa'..'ac'],
|
27
|
+
method_name: 'to_a',
|
28
|
+
expected: [*'aa'..'ac'],
|
28
29
|
},
|
29
30
|
]
|
30
31
|
|
@@ -37,7 +38,11 @@ describe Array do
|
|
37
38
|
# nothing
|
38
39
|
|
39
40
|
# -- when/then --
|
40
|
-
|
41
|
+
if c[:args]
|
42
|
+
actual = c[:input].>>.send c[:method_name], *c[:args]
|
43
|
+
else
|
44
|
+
actual = c[:input].>>.send c[:method_name]
|
45
|
+
end
|
41
46
|
|
42
47
|
expect(actual).to eq(c[:expected])
|
43
48
|
ensure
|
@@ -7,24 +7,18 @@ describe String do
|
|
7
7
|
cases = [
|
8
8
|
{
|
9
9
|
case_no: 1,
|
10
|
-
case_title: '
|
10
|
+
case_title: 'no args case',
|
11
11
|
input: 'abc',
|
12
|
-
method_name: '
|
13
|
-
expected:
|
12
|
+
method_name: 'next',
|
13
|
+
expected: 'bcd',
|
14
14
|
},
|
15
15
|
{
|
16
16
|
case_no: 2,
|
17
|
-
case_title: '
|
17
|
+
case_title: 'have args case',
|
18
18
|
input: 'abc',
|
19
|
-
method_name:
|
20
|
-
|
21
|
-
|
22
|
-
{
|
23
|
-
case_no: 3,
|
24
|
-
case_title: 'proc case',
|
25
|
-
input: 'abc',
|
26
|
-
method_name: -> (x) { (x.ord + 2).chr },
|
27
|
-
expected: ['c', 'd', 'e'],
|
19
|
+
method_name: '+',
|
20
|
+
args: ['d'],
|
21
|
+
expected: 'adbdcd',
|
28
22
|
},
|
29
23
|
]
|
30
24
|
|
@@ -37,7 +31,11 @@ describe String do
|
|
37
31
|
# nothing
|
38
32
|
|
39
33
|
# -- when/then --
|
40
|
-
|
34
|
+
if c[:args]
|
35
|
+
actual = c[:input].>> c[:method_name], *c[:args]
|
36
|
+
else
|
37
|
+
actual = c[:input].>> c[:method_name]
|
38
|
+
end
|
41
39
|
|
42
40
|
expect(actual).to eq(c[:expected])
|
43
41
|
ensure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tbpgr_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.124
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tbpgr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|