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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67f2d5979271ec5df878cc2957ef7eea5673f694
4
- data.tar.gz: 15b4aeee1a79eaca06678f7734db27ff42a0620d
3
+ metadata.gz: abc47f0e31b15cdf12a627961e0f4c286731db50
4
+ data.tar.gz: c96f77f49a40f07e6aabf03644ac57235bcbd60a
5
5
  SHA512:
6
- metadata.gz: 0ff017cd57605cecd33155bf5674338ce7dd9d38c28589d1fae899980b91cbf357ce8a52e066bba13d8da8c49464ba00926a2d6f5ce84169c9cb4ad3e03d4d80
7
- data.tar.gz: 7b7b8d716d9d70576b486eca511c53db833e04b470d2d40d55fdf6b8dbe3171b3571dded28b25391d738da87c32d047a68a4de06d7621ee927c966e36f5df07b
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) |alias of map(&:method_symbol) |
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']>>:ord # => [97, 98, 99]
171
- [*'a'..'c']>>:upcase # => ["A", "B", "C"]
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">>:ord # => [97, 98, 99]
3031
- "abc">>'ord' # => [97, 98, 99]
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
- # alias of map(&:method_symbol)
29
+ # return ArrayContext for each execute
6
30
  #
7
31
  # === Example
8
32
  #
9
- # [*'a'..'c']>>:ord # => [97, 98, 99]
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 >>(method_name)
12
- return self unless [Symbol, String].include? method_name.class
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 converto to Array. and applya operator to execute elements
6
+ # self convert to Array. execute each elements
6
7
  #
7
8
  # === Example
8
9
  #
9
- # "abc">>:ord # => [97, 98, 99]
10
- # "abc">>'ord' # => [97, 98, 99]
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
- if method_name.is_a? Proc
16
- split('').map { |v|method_name[v] }
17
- else
18
- split('').map(&method_name.to_sym)
19
- end
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.123'
5
+ VERSION = '0.0.124'
6
6
  end
@@ -7,24 +7,25 @@ describe Array do
7
7
  cases = [
8
8
  {
9
9
  case_no: 1,
10
- case_title: 'valid case',
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: 2,
17
- case_title: 'valid case',
18
- input: [*'a'..'c'],
19
- method_name: 'ord',
20
- expected: [97, 98, 99],
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: 3,
24
- case_title: 'valid case',
25
- input: [*'a'..'c'],
26
- method_name: 1,
27
- expected: [*'a'..'c'],
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
- actual = c[:input] >> c[:method_name]
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: 'string method case',
10
+ case_title: 'no args case',
11
11
  input: 'abc',
12
- method_name: 'ord',
13
- expected: [97, 98, 99],
12
+ method_name: 'next',
13
+ expected: 'bcd',
14
14
  },
15
15
  {
16
16
  case_no: 2,
17
- case_title: 'symbol case',
17
+ case_title: 'have args case',
18
18
  input: 'abc',
19
- method_name: :ord,
20
- expected: [97, 98, 99],
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
- actual = c[:input] >> c[:method_name]
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.123
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-10 00:00:00.000000000 Z
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport