tbpgr_utils 0.0.132 → 0.0.133

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa077187bcfddd3a88184d5d807f7edf64fd0bb6
4
- data.tar.gz: 5f826256f5d4b1dfb81a28309d5b122fa709edf5
3
+ metadata.gz: 592b524e7890f468f0556d8a8d49a268b2b47e2d
4
+ data.tar.gz: 43e45548a0a903bf0e1a45f5547fd78870d68dc7
5
5
  SHA512:
6
- metadata.gz: 9d7d644a0b83a1e3c68154bf66f37b21fccaa4e8ebca087aaad9237057924bd7693019679e6328cd723fd93ecc46dd7576d8f986dbd19fc2e5e169897f1e3811
7
- data.tar.gz: 49afb39e2da60d6a40b3193d5dfee19e050bf59fbf598e573bf00b30a00c0885915b1b15b5f66291e31063bc0ff9e1e8249f604d34dba5b9c5af0b8fd1770288
6
+ metadata.gz: a2fbfe83d0470ad3d6dd2ed8b7cbbc7433c72bb628eddf177aa3f2aedd1e107397f95ff2a6d7660d2745e981cba1ba24b4a7c302790519fa635e6c3f7cb3e1e5
7
+ data.tar.gz: 17cd4dc49a6bf8ea35fccb9573c0db90d9ee2b1eebaeb63627b847a7bedd9441e207494c6d1b1faf9008fa5a3178f9fd93b388073fe62b0f3eadcdcbbf1aae22
data/README.md CHANGED
@@ -89,6 +89,7 @@ Or install it yourself as:
89
89
  |[TbpgrUtils Hash#html_table](#hashhtml_table) |get html table string from key + value |
90
90
  |[TbpgrUtils Hash#table](#hashtable) |get pipe format table string from key + value |
91
91
  |[TbpgrUtils Integer#each_digit](#integereach_digit) |provide iterator for number's each digit |
92
+ |[TbpgrUtils Integer#each_digit_with_index](#integereach_digit_with_index) |provide iterator for number's each digit with index |
92
93
  |[TbpgrUtils Integer#palindromic_prime?](#integerpalindromic_prime) |Returns true if value is palindromic prime, false for a composite. |
93
94
  |[TbpgrUtils Kernel booleans](#kerne-booleans) |True or False instance aliases. |
94
95
  |[TbpgrUtils Kernel#bulk_define_methods](#kernelbulk_define_methods) |define methods to classes. methods have simple return value. |
@@ -1549,11 +1550,21 @@ result
1549
1550
 
1550
1551
  [back to list](#list)
1551
1552
 
1553
+ ### Integer#each_digit_with_index
1554
+ ~~~ruby
1555
+ require 'tbpgr_utils'
1556
+ ret=[];
1557
+ 12345.each_digit_with_index { |v, i|ret << v + i };
1558
+ print ret # => [1, 3, 5, 7, 9]
1559
+ ~~~
1560
+
1561
+ [back to list](#list)
1562
+
1552
1563
  ### Integer#each_digit
1553
1564
  ~~~ruby
1554
1565
  require 'tbpgr_utils'
1555
1566
  ret=[];
1556
- 12345.each_digit { |v|ret << v+1 };
1567
+ 12345.each_digit { |v|ret << v + 1 };
1557
1568
  print ret # => [2,3,4,5,6]
1558
1569
  ~~~
1559
1570
 
@@ -3780,6 +3791,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3780
3791
  https://github.com/tbpgr/tbpgr_utils_snippets
3781
3792
 
3782
3793
  ## History
3794
+ * version 0.0.133 : add Integer#each_digit_with_index
3783
3795
  * version 0.0.132 : add Integer#each_digit
3784
3796
  * version 0.0.131 : add Object#grep_protected_instance_method, Object#grep_private_instance_method
3785
3797
  * version 0.0.130 : add Object#grep_method
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ class Integer
4
+ # provide iterator for number's each digit with index
5
+ #
6
+ # === Example
7
+ #
8
+ # ret=[];12_345.each_digit_with_index { |v, i|ret << v + i };print ret # => [1, 3, 5, 7, 9]
9
+ #
10
+ def each_digit_with_index
11
+ abs.to_s.split('').map { |v|v.to_i }.each_with_index { |v, i|yield(v, i) }
12
+ end
13
+ end
@@ -1,3 +1,4 @@
1
1
  # encoding: utf-8
2
2
  require 'open_classes/integer/each_digit'
3
+ require 'open_classes/integer/each_digit_with_index'
3
4
  require 'open_classes/integer/palindromic_prime'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.132'
5
+ VERSION = '0.0.133'
6
6
  end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'open_classes/integer/each_digit_with_index'
4
+
5
+ describe Integer do
6
+ context :each_digit_with_index do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'valid case',
11
+ input: 12_345,
12
+ expected: [1, 3, 5, 7, 9],
13
+ },
14
+ ]
15
+
16
+ cases.each do |c|
17
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
18
+ begin
19
+ case_before c
20
+
21
+ # -- given --
22
+ # nothing
23
+
24
+ # -- when --
25
+ actual = []
26
+ c[:input].each_digit_with_index { |v, i|actual << v + i }
27
+
28
+ # -- then --
29
+ expect(actual).to eq(c[:expected])
30
+ ensure
31
+ case_after c
32
+ end
33
+ end
34
+
35
+ def case_before(c)
36
+ # implement each case before
37
+ end
38
+
39
+ def case_after(c)
40
+ # implement each case after
41
+ end
42
+ end
43
+ end
44
+ end
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.132
4
+ version: 0.0.133
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-19 00:00:00.000000000 Z
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -178,6 +178,7 @@ files:
178
178
  - lib/open_classes/hash/table.rb
179
179
  - lib/open_classes/integer.rb
180
180
  - lib/open_classes/integer/each_digit.rb
181
+ - lib/open_classes/integer/each_digit_with_index.rb
181
182
  - lib/open_classes/integer/palindromic_prime.rb
182
183
  - lib/open_classes/kernel.rb
183
184
  - lib/open_classes/kernel/aa_ancestors.rb
@@ -319,6 +320,7 @@ files:
319
320
  - spec/open_classes/hash/html_table_spec.rb
320
321
  - spec/open_classes/hash/table_spec.rb
321
322
  - spec/open_classes/integer/each_digit_spec.rb
323
+ - spec/open_classes/integer/each_digit_with_index_spec.rb
322
324
  - spec/open_classes/integer/palindromic_prime_spec.rb
323
325
  - spec/open_classes/kernel/aa_ancestors_spec.rb
324
326
  - spec/open_classes/kernel/booleans_spec.rb
@@ -480,6 +482,7 @@ test_files:
480
482
  - spec/open_classes/hash/html_table_spec.rb
481
483
  - spec/open_classes/hash/table_spec.rb
482
484
  - spec/open_classes/integer/each_digit_spec.rb
485
+ - spec/open_classes/integer/each_digit_with_index_spec.rb
483
486
  - spec/open_classes/integer/palindromic_prime_spec.rb
484
487
  - spec/open_classes/kernel/aa_ancestors_spec.rb
485
488
  - spec/open_classes/kernel/booleans_spec.rb