tbpgr_utils 0.0.34 → 0.0.35

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.
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ gemspec
4
4
  gem "rspec", "~> 2.14.1"
5
5
  gem "activesupport", "~> 4.0.1"
6
6
  gem "simplecov", "~> 0.8.2"
7
+ group :test do
8
+ gem 'coveralls', require: false
9
+ end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # TbpgrUtils
2
2
 
3
3
  [![Build Status](https://travis-ci.org/tbpgr/tbpgr_utils.png?branch=master)](https://travis-ci.org/tbpgr/tbpgr_utils)
4
+ [![Coverage Status](https://coveralls.io/repos/tbpgr/tbpgr_utils/badge.png)](https://coveralls.io/r/tbpgr/tbpgr_utils)
4
5
 
5
6
  TbpgrUtils is Utilities.
6
7
 
@@ -40,6 +41,7 @@ Or install it yourself as:
40
41
  |[TbpgrUtils Array#together_last](#arraytogether_last) |together version of Array#last. together_last has alias :tlast |
41
42
  |[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
42
43
  |[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!] |
44
+ |[TbpgrUtils Array#together_pop](#arraytogether_pop) |together version of Array#pop. together_pop has alias :tpop |
43
45
  |[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
44
46
  |[TbpgrUtils Array#together_select](#arraytogether_selector-tselect-together_find_all-tfindall) |together version of Enumerable#select. together_select has aliases [:tselect, :together_find_all, :tfindall] |
45
47
  |[TbpgrUtils Array#together_shift](#arraytogether_shift) |together version of Array#shift. together_shift has alias :tshift |
@@ -522,6 +524,41 @@ print ary # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:
522
524
 
523
525
  [back to list](#list)
524
526
 
527
+ ### Array#together_pop(or tpop)
528
+ together_pop has alias :tpop
529
+
530
+ not empty case
531
+ ~~~ruby
532
+ lists = [[1, 2], [5, 6]]
533
+ ret = lists.together_pop
534
+ print ret # => [2, 6]
535
+ print lists # => [1, 5]
536
+ ~~~
537
+
538
+ empty case
539
+ ~~~ruby
540
+ lists = [[], []]
541
+ ret = lists.together_pop
542
+ print ret # => [nil, nil]
543
+ print lists # => [[], []]
544
+ ~~~
545
+
546
+ not empty case with args
547
+ lists = [[1, 2], [5, 6]]
548
+ ret = lists.together_pop 2
549
+ print ret # => [[1, 2], [5, 6]]
550
+ print lists # => [[], []]
551
+ ~~~
552
+
553
+ not empty case with args
554
+ lists = [[], []]
555
+ ret = lists.together_pop 2
556
+ print ret # => [[], []]
557
+ print lists # => [[], []]
558
+ ~~~
559
+
560
+ [back to list](#list)
561
+
525
562
  ### Array#together_reduce(or :treduce, :together_inject, :tinject)
526
563
  * if you want to single return
527
564
 
@@ -1249,6 +1286,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
1249
1286
  https://github.com/tbpgr/tbpgr_utils_snippets
1250
1287
 
1251
1288
  ## History
1289
+ * version 0.0.35 : add Array#together_pop(alias tpop).
1252
1290
  * version 0.0.34 : add Array#together_last(alias tlast).
1253
1291
  * version 0.0.33 : add Array#together_shift(alias tshift).
1254
1292
  * version 0.0.32 : add Array#together_insert(alias tinsert).
@@ -533,7 +533,6 @@ class Array
533
533
  each { |list|list.insert(index, *args) }
534
534
  end
535
535
 
536
-
537
536
  # Arrays bulk shift.
538
537
  #
539
538
  # together_shift has alias :tshift
@@ -570,6 +569,42 @@ class Array
570
569
  end
571
570
  end
572
571
 
572
+ # Arrays bulk pop.
573
+ #
574
+ # together_pop has alias :tpop
575
+ #
576
+ # not empty case
577
+ # lists = [[1, 2], [5, 6]]
578
+ # ret = lists.together_pop
579
+ # print ret # => [2, 6]
580
+ # print lists # => [1, 5]
581
+ #
582
+ # empty case
583
+ # lists = [[], []]
584
+ # ret = lists.together_pop
585
+ # print ret # => [nil, nil]
586
+ # print lists # => [[], []]
587
+ #
588
+ # not empty case with args
589
+ # lists = [[1, 2], [5, 6]]
590
+ # ret = lists.together_pop 2
591
+ # print ret # => [[1, 2], [5, 6]]
592
+ # print lists # => [[], []]
593
+ #
594
+ # not empty case with args
595
+ # lists = [[], []]
596
+ # ret = lists.together_pop 2
597
+ # print ret # => [[], []]
598
+ # print lists # => [[], []]
599
+ def together_pop(count = nil)
600
+ if_not_contain_array_rails_type_error
601
+ if count.nil?
602
+ reduce([]) { |ret, list|ret << list.pop }
603
+ else
604
+ reduce([]) { |ret, list|ret << list.pop(count) }
605
+ end
606
+ end
607
+
573
608
  private
574
609
 
575
610
  def if_not_contain_array_rails_type_error
@@ -633,6 +668,7 @@ class Array
633
668
  alias_method :tindex, :together_index
634
669
  alias_method :tinsert, :together_insert
635
670
  alias_method :tshift, :together_shift
671
+ alias_method :tpop, :together_pop
636
672
  alias_methods [:together_collect, :tmap, :tcollect], :together_map
637
673
  alias_methods [:together_collect!, :tmap!, :tcollect!], :together_map!
638
674
  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.34'
5
+ VERSION = '0.0.35'
6
6
  end
@@ -1304,7 +1304,6 @@ describe Array do
1304
1304
  end
1305
1305
  end
1306
1306
 
1307
-
1308
1307
  context :together_shift do
1309
1308
  cases = [
1310
1309
  {
@@ -1362,7 +1361,7 @@ describe Array do
1362
1361
  has_args: true,
1363
1362
  },
1364
1363
  {
1365
- case_no: 1,
1364
+ case_no: 7,
1366
1365
  case_title: 'not empty case(alias tshift)',
1367
1366
  inputs: [[1, 2], [5, 6]],
1368
1367
  method_name: 'tshift',
@@ -1483,4 +1482,104 @@ describe Array do
1483
1482
  end
1484
1483
  end
1485
1484
  end
1485
+
1486
+ context :together_pop do
1487
+ cases = [
1488
+ {
1489
+ case_no: 1,
1490
+ case_title: 'not empty case',
1491
+ inputs: [[1, 2], [5, 6]],
1492
+ method_name: 'together_pop',
1493
+ expected_ret: [2, 6],
1494
+ expected_self: [[1], [5]],
1495
+ },
1496
+ {
1497
+ case_no: 2,
1498
+ case_title: 'one empty case',
1499
+ inputs: [[1, 2], []],
1500
+ method_name: 'together_pop',
1501
+ expected_ret: [2, nil],
1502
+ expected_self: [[1], []],
1503
+ },
1504
+ {
1505
+ case_no: 3,
1506
+ case_title: 'both empty case',
1507
+ inputs: [[], []],
1508
+ method_name: 'together_pop',
1509
+ expected_ret: [nil, nil],
1510
+ expected_self: [[], []],
1511
+ },
1512
+ {
1513
+ case_no: 4,
1514
+ case_title: 'not empty, has args case',
1515
+ inputs: [[1, 2], [5, 6]],
1516
+ method_name: 'together_pop',
1517
+ args: 2,
1518
+ expected_ret: [[1, 2], [5, 6]],
1519
+ expected_self: [[], []],
1520
+ has_args: true,
1521
+ },
1522
+ {
1523
+ case_no: 5,
1524
+ case_title: 'one empty, has args case',
1525
+ inputs: [[1, 2], []],
1526
+ method_name: 'together_pop',
1527
+ args: 2,
1528
+ expected_ret: [[1, 2], []],
1529
+ expected_self: [[], []],
1530
+ has_args: true,
1531
+ },
1532
+ {
1533
+ case_no: 6,
1534
+ case_title: 'both empty, has args case',
1535
+ inputs: [[], []],
1536
+ method_name: 'together_pop',
1537
+ args: 2,
1538
+ expected_ret: [[], []],
1539
+ expected_self: [[], []],
1540
+ has_args: true,
1541
+ },
1542
+ {
1543
+ case_no: 7,
1544
+ case_title: 'not empty case(alias tpop)',
1545
+ inputs: [[1, 2], [5, 6]],
1546
+ method_name: 'tpop',
1547
+ expected_ret: [1, 5],
1548
+ expected_self: [[2], [6]],
1549
+ },
1550
+ ]
1551
+
1552
+ cases.each do |c|
1553
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
1554
+ begin
1555
+ case_before c
1556
+
1557
+ # -- given --
1558
+ # nothing
1559
+
1560
+ # -- when --
1561
+ actual = \
1562
+ if c[:has_args]
1563
+ c[:inputs].send c[:method_name], c[:args]
1564
+ else
1565
+ c[:inputs].send c[:method_name]
1566
+ end
1567
+
1568
+ # -- then --
1569
+ expect(actual).to eq(c[:expected_ret])
1570
+ expect(c[:inputs]).to eq(c[:expected_self])
1571
+ ensure
1572
+ case_after c
1573
+ end
1574
+ end
1575
+
1576
+ def case_before(c)
1577
+ # implement each case before
1578
+ end
1579
+
1580
+ def case_after(c)
1581
+ # implement each case after
1582
+ end
1583
+ end
1584
+ end
1486
1585
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  # encoding: utf-8
2
2
  require 'simplecov'
3
- SimpleCov.start
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter "/spec/"
11
+ end
4
12
  RSpec.configure do |config|
5
13
  config.treat_symbols_as_metadata_keys_with_true_values = true
6
14
  config.run_all_when_everything_filtered = true
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.34
4
+ version: 0.0.35
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-10 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &28452540 !ruby/object:Gem::Requirement
16
+ requirement: &28801860 !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: *28452540
24
+ version_requirements: *28801860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &28452252 !ruby/object:Gem::Requirement
27
+ requirement: &28801428 !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: *28452252
35
+ version_requirements: *28801428
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &28452024 !ruby/object:Gem::Requirement
38
+ requirement: &28800936 !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: *28452024
46
+ version_requirements: *28800936
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &28451700 !ruby/object:Gem::Requirement
49
+ requirement: &28800480 !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: *28451700
57
+ version_requirements: *28800480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &28451400 !ruby/object:Gem::Requirement
60
+ requirement: &28800036 !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: *28451400
68
+ version_requirements: *28800036
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - .coveralls.yml
76
77
  - .gitignore
77
78
  - .rspec
78
79
  - .rubocop.yml