tbpgr_utils 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,6 +33,7 @@ Or install it yourself as:
33
33
  |[TbpgrUtils Array#together_fill](#arraytogether_fill) |together version of Array#fill. together_fill has alias :tfill |
34
34
  |[TbpgrUtils Array#together_first](#arraytogether_first) |together version of Array#first. together_first has alias :tfirst |
35
35
  |[TbpgrUtils Array#together_include?](#arraytogether_include) |together version of Array#include?. together_include? has alias :tinclude? |
36
+ |[TbpgrUtils Array#together_index](#arraytogether_index) |together version of Array#index. together_index has alias :tindex |
36
37
  |[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
37
38
  |[TbpgrUtils Array#together_map!](#arraytogether_map-1or-tmap-1-together_collect-1-tcollect-1) |together version of Enumerable#map!. together_map! has aliases [:tmap!, :together_collect!, :tcollect!] |
38
39
  |[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
@@ -378,6 +379,32 @@ both not include multi ret case
378
379
 
379
380
  [back to list](#list)
380
381
 
382
+ ### Array#together_index
383
+ together_index has alias :tindex
384
+
385
+ both index exist case
386
+ ~~~ruby
387
+ lists = [[*1..5], [*5..9]]
388
+ ret = lists.together_index 5
389
+ print ret # => [4, 0]
390
+ ~~~
391
+
392
+ one include single ret case
393
+ ~~~ruby
394
+ lists = [[*1..5], [*5..9]]
395
+ ret = lists.together_index 4
396
+ print ret # => [3, nil]
397
+ ~~~
398
+
399
+ both not include single ret case
400
+ ~~~ruby
401
+ lists = [[*1..5], [*5..9]]
402
+ ret = lists.together_index 10
403
+ print ret # => [nil, nil]
404
+ ~~~
405
+
406
+ [back to list](#list)
407
+
381
408
  ### Array#together_map(or tmap, together_collect, tcollect)
382
409
  ~~~ruby
383
410
  require 'tbpgr_utils'
@@ -1121,6 +1148,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
1121
1148
  https://github.com/tbpgr/tbpgr_utils_snippets
1122
1149
 
1123
1150
  ## History
1151
+ * version 0.0.31 : add Array#together_index(alias tindex).
1124
1152
  * version 0.0.30 : add Array#together_include?(alias tinclude?).
1125
1153
  * version 0.0.29 : add Array#together_first(alias tfirst).
1126
1154
  * version 0.0.28 : add Array#together_fill(alias tfill). add File.insert_bom.
@@ -458,6 +458,29 @@ class Array
458
458
  reduce(false) { |ret, list|ret = ret || list.include?(value) }
459
459
  end
460
460
 
461
+ # Arrays bulk index.
462
+ #
463
+ # together_index has alias :tindex
464
+ #
465
+ # both index exist case
466
+ # lists = [[*1..5], [*5..9]]
467
+ # ret = lists.together_index 5
468
+ # print ret # => [4, 0]
469
+ #
470
+ # one include single ret case
471
+ # lists = [[*1..5], [*5..9]]
472
+ # ret = lists.together_index 4
473
+ # print ret # => [3, nil]
474
+ #
475
+ # both not include single ret case
476
+ # lists = [[*1..5], [*5..9]]
477
+ # ret = lists.together_index 10
478
+ # print ret # => [nil, nil]
479
+ def together_index(value)
480
+ if_not_contain_array_rails_type_error
481
+ reduce([]) { |ret, list|ret << list.index(value) }
482
+ end
483
+
461
484
  private
462
485
 
463
486
  def if_not_contain_array_rails_type_error
@@ -517,6 +540,7 @@ class Array
517
540
  alias_method :tfill, :together_fill
518
541
  alias_method :tfirst, :together_first
519
542
  alias_method :tinclude?, :together_include?
543
+ alias_method :tindex, :together_index
520
544
  alias_methods [:together_collect, :tmap, :tcollect], :together_map
521
545
  alias_methods [:together_collect!, :tmap!, :tcollect!], :together_map!
522
546
  alias_methods [:together_find_all, :tselect, :tfindall], :together_select
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.30'
5
+ VERSION = '0.0.31'
6
6
  end
@@ -1179,4 +1179,68 @@ describe Array do
1179
1179
  end
1180
1180
  end
1181
1181
  end
1182
+
1183
+ context :together_index do
1184
+ cases = [
1185
+ {
1186
+ case_no: 1,
1187
+ case_title: 'both index exist case',
1188
+ inputs: [[*1..5], [*5..9]],
1189
+ value: 5,
1190
+ method_name: :together_index,
1191
+ expected: [4, 0],
1192
+ },
1193
+ {
1194
+ case_no: 2,
1195
+ case_title: 'one index exist case',
1196
+ inputs: [[*1..5], [*5..9]],
1197
+ value: 4,
1198
+ method_name: :together_index,
1199
+ expected: [3, nil],
1200
+ },
1201
+ {
1202
+ case_no: 3,
1203
+ case_title: 'both not exist index case',
1204
+ inputs: [[*1..5], [*5..9]],
1205
+ value: 10,
1206
+ method_name: :together_index,
1207
+ expected: [nil, nil],
1208
+ },
1209
+ {
1210
+ case_no: 4,
1211
+ case_title: 'both index exist case(alias tindex)',
1212
+ inputs: [[*1..5], [*5..9]],
1213
+ value: 5,
1214
+ method_name: :tindex,
1215
+ expected: [4, 0],
1216
+ },
1217
+ ]
1218
+
1219
+ cases.each do |c|
1220
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
1221
+ begin
1222
+ case_before c
1223
+
1224
+ # -- given --
1225
+ # nothing
1226
+
1227
+ # -- when --
1228
+ actual = c[:inputs].send c[:method_name], c[:value]
1229
+
1230
+ # -- then --
1231
+ expect(actual).to eq(c[:expected])
1232
+ ensure
1233
+ case_after c
1234
+ end
1235
+ end
1236
+
1237
+ def case_before(c)
1238
+ # implement each case before
1239
+ end
1240
+
1241
+ def case_after(c)
1242
+ # implement each case after
1243
+ end
1244
+ end
1245
+ end
1182
1246
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbpgr_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.31
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-06 00:00:00.000000000 Z
12
+ date: 2014-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &27941640 !ruby/object:Gem::Requirement
16
+ requirement: &29345544 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *27941640
24
+ version_requirements: *29345544
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &27941196 !ruby/object:Gem::Requirement
27
+ requirement: &29345256 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *27941196
35
+ version_requirements: *29345256
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &27940872 !ruby/object:Gem::Requirement
38
+ requirement: &29345028 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *27940872
46
+ version_requirements: *29345028
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &29420712 !ruby/object:Gem::Requirement
49
+ requirement: &29344704 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.14.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *29420712
57
+ version_requirements: *29344704
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &29420412 !ruby/object:Gem::Requirement
60
+ requirement: &29344404 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.8.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *29420412
68
+ version_requirements: *29344404
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp