tbpgr_utils 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,6 +27,7 @@ Or install it yourself as:
27
27
  |[TbpgrUtils Array#together_compact!](#arraytogether_compact-1) |together version of Array#compact!. together_compact! has alias :tcompact! this is mutable. |
28
28
  |[TbpgrUtils Array#together_concat](#arraytogether_concat) |together version of Array#concat. together_concat has alias :tconcat |
29
29
  |[TbpgrUtils Array#together_delete](#arraytogether_delete) |together version of Array#delete. together_delete has alias :tdelete |
30
+ |[TbpgrUtils Array#together_delete_at](#arraytogether_delete_at) |together version of Array#delete_at. together_delete_at has alias :tdelete_at |
30
31
  |[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
31
32
  |[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!] |
32
33
  |[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
@@ -172,6 +173,45 @@ print lists # => output [[1, 2, 3, 4], [2, 3, 4, 5]]
172
173
 
173
174
  [back to list](#list)
174
175
 
176
+ ### Array#together_delete_at
177
+ if delete_at target is exist
178
+ ~~~ruby
179
+ require 'tbpgr_utils'
180
+
181
+ child1 = [1, 2, 3, 4]
182
+ child2 = [2, 3, 4, 5]
183
+ lists = [child1, child2]
184
+ ret = lists.together_delete_at 2
185
+ print ret # => [3, 4]
186
+ print lists # => output [[1, 2, 4], [2, 3, 5]]
187
+ ~~~
188
+
189
+ if delete_at target is not exist
190
+ ~~~ruby
191
+ require 'tbpgr_utils'
192
+
193
+ child1 = [1, 2, 3, 4]
194
+ child2 = [2, 3, 4, 5]
195
+ lists = [child1, child2]
196
+ ret = lists.together_delete_at 6
197
+ print ret # => [nil, nil]
198
+ print lists # => output [[1, 2, 3, 4], [2, 3, 4, 5]]
199
+ ~~~
200
+
201
+ if delete_at target is exist(minus index)
202
+ ~~~ruby
203
+ require 'tbpgr_utils'
204
+
205
+ child1 = [1, 2, 3, 4]
206
+ child2 = [2, 3, 4, 5]
207
+ lists = [child1, child2]
208
+ ret = lists.together_delete_at -3
209
+ print ret # => [2, 3]
210
+ print lists # => output [[1, 3, 4], [2, 4, 5]]
211
+ ~~~
212
+
213
+ [back to list](#list)
214
+
175
215
  ### Array#together_map(or tmap, together_collect, tcollect)
176
216
  ~~~ruby
177
217
  require 'tbpgr_utils'
@@ -896,6 +936,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
896
936
  https://github.com/tbpgr/tbpgr_utils_snippets
897
937
 
898
938
  ## History
939
+ * version 0.0.25 : add Array#together_delete_at(alias tdelete_at)
899
940
  * version 0.0.24 : add Array#together_delete(alias tdelete)
900
941
  * version 0.0.23 : add Array#together_map!(aliases => [tmap!, together_collect!, tcollect!])
901
942
  * version 0.0.22 : add Array#together_compact. together_compact has alias :tcompact. Array#together_compact!. together_compact! has alias :tcompact!.
@@ -279,6 +279,38 @@ class Array
279
279
  ret.compact.size == 0 ? default_return : value
280
280
  end
281
281
 
282
+ # Arrays bulk delete_at.
283
+ #
284
+ # together_delete_at has alias :tdelete_at
285
+ #
286
+ # if delete_at target is exist
287
+ # child1 = [1, 2, 3, 4]
288
+ # child2 = [2, 3, 4, 5]
289
+ # lists = [child1, child2]
290
+ # ret = lists.together_delete_at 2
291
+ # print ret # => [3, 4]
292
+ # print lists # => output [[1, 2, 4], [2, 3, 5]]
293
+ #
294
+ # if delete_at target is not exist
295
+ # child1 = [1, 2, 3, 4]
296
+ # child2 = [2, 3, 4, 5]
297
+ # lists = [child1, child2]
298
+ # ret = lists.together_delete_at 6
299
+ # print ret # => [nil, nil]
300
+ # print lists # => output [[1, 2, 3, 4], [2, 3, 4, 5]]
301
+ #
302
+ # if delete_at target is exist(minus index)
303
+ # child1 = [1, 2, 3, 4]
304
+ # child2 = [2, 3, 4, 5]
305
+ # lists = [child1, child2]
306
+ # ret = lists.together_delete_at -3
307
+ # print ret # => [2, 3]
308
+ # print lists # => output [[1, 3, 4], [2, 4, 5]]
309
+ def together_delete_at(index)
310
+ if_not_contain_array_rails_type_error
311
+ reduce([]) { |ret, list|ret << list.delete_at(index) }
312
+ end
313
+
282
314
  private
283
315
 
284
316
  def if_not_contain_array_rails_type_error
@@ -342,6 +374,7 @@ class Array
342
374
  alias_method :tcompact, :together_compact
343
375
  alias_method :tcompact!, :together_compact!
344
376
  alias_method :tdelete, :together_delete
377
+ alias_method :tdelete_at, :together_delete_at
345
378
  alias_methods [:together_collect, :tmap, :tcollect], :together_map
346
379
  alias_methods [:together_collect!, :tmap!, :tcollect!], :together_map!
347
380
  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.24'
5
+ VERSION = '0.0.25'
6
6
  end
@@ -749,4 +749,78 @@ describe Array do
749
749
  end
750
750
  end
751
751
  end
752
+
753
+
754
+ context :together_delete_at do
755
+ cases = [
756
+ {
757
+ case_no: 1,
758
+ case_title: 'valid case',
759
+ inputs: [[1, 2, 3, 4], [2, 3, 4, 5]],
760
+ delete_value: 2,
761
+ method_name: :together_delete_at,
762
+ expected: [[1, 2, 4], [2, 3, 5]],
763
+ ret: [3, 4],
764
+ },
765
+ {
766
+ case_no: 2,
767
+ case_title: 'valid case(not exist)',
768
+ inputs: [[1, 2, 3, 4], [2, 3, 4, 5]],
769
+ delete_value: 5,
770
+ method_name: :together_delete_at,
771
+ expected: [[1, 2, 3, 4], [2, 3, 4, 5]],
772
+ ret: [nil, nil],
773
+ },
774
+ {
775
+ case_no: 3,
776
+ case_title: 'valid case(minus index)',
777
+ inputs: [[1, 2, 3, 4], [2, 3, 4, 5]],
778
+ delete_value: -3,
779
+ method_name: :together_delete_at,
780
+ expected: [[1, 3, 4], [2, 4, 5]],
781
+ ret: [2, 3],
782
+ },
783
+ {
784
+ case_no: 1,
785
+ case_title: 'valid case(use tdelete_at alias)',
786
+ inputs: [[1, 2, 3, 4], [2, 3, 4, 5]],
787
+ delete_value: 2,
788
+ method_name: :tdelete_at,
789
+ expected: [[1, 2, 4], [2, 3, 5]],
790
+ ret: [3, 4],
791
+ },
792
+ ]
793
+
794
+ cases.each do |c|
795
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
796
+ begin
797
+ case_before c
798
+
799
+ # -- given --
800
+ # nothing
801
+
802
+ # -- when --
803
+ if c[:has_block]
804
+ actual = c[:inputs].send c[:method_name], c[:delete_value] {c[:block] }
805
+ else
806
+ actual = c[:inputs].send c[:method_name], c[:delete_value]
807
+ end
808
+
809
+ # -- then --
810
+ expect(actual).to eq(c[:ret])
811
+ expect(c[:inputs]).to eq(c[:expected])
812
+ ensure
813
+ case_after c
814
+ end
815
+ end
816
+
817
+ def case_before(c)
818
+ # implement each case before
819
+ end
820
+
821
+ def case_after(c)
822
+ # implement each case after
823
+ end
824
+ end
825
+ end
752
826
  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.24
4
+ version: 0.0.25
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-01-31 00:00:00.000000000 Z
12
+ date: 2014-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &28904244 !ruby/object:Gem::Requirement
16
+ requirement: &21008076 !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: *28904244
24
+ version_requirements: *21008076
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &28903836 !ruby/object:Gem::Requirement
27
+ requirement: &21007740 !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: *28903836
35
+ version_requirements: *21007740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &28903464 !ruby/object:Gem::Requirement
38
+ requirement: &21007380 !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: *28903464
46
+ version_requirements: *21007380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &28902816 !ruby/object:Gem::Requirement
49
+ requirement: &21006912 !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: *28902816
57
+ version_requirements: *21006912
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &28924764 !ruby/object:Gem::Requirement
60
+ requirement: &21006408 !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: *28924764
68
+ version_requirements: *21006408
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp