tbpgr_utils 0.0.133 → 0.0.134

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: 592b524e7890f468f0556d8a8d49a268b2b47e2d
4
- data.tar.gz: 43e45548a0a903bf0e1a45f5547fd78870d68dc7
3
+ metadata.gz: adc75672841e4e6947c4bd2b8098bc42e098ff00
4
+ data.tar.gz: 2843ff2a1231c7ba79d6f28ed44a28bb412e9a89
5
5
  SHA512:
6
- metadata.gz: a2fbfe83d0470ad3d6dd2ed8b7cbbc7433c72bb628eddf177aa3f2aedd1e107397f95ff2a6d7660d2745e981cba1ba24b4a7c302790519fa635e6c3f7cb3e1e5
7
- data.tar.gz: 17cd4dc49a6bf8ea35fccb9573c0db90d9ee2b1eebaeb63627b847a7bedd9441e207494c6d1b1faf9008fa5a3178f9fd93b388073fe62b0f3eadcdcbbf1aae22
6
+ metadata.gz: f78dad0412e431370316661370874e5a24ed8a5eab127345b9748c3f5927565f62d9c44b19d0f1b511a53d2ebd38bf269ac425d1363c7189779dfdc42b294844
7
+ data.tar.gz: adc2fa6355b9d297c60b90afef824dc7c70a650ea3c43f6f05469b0c5c67836e0ff21090a296e55526c7a8883f3dbbef651fb4fe7dcb609d9e13c84058ede9e3
data/README.md CHANGED
@@ -91,6 +91,7 @@ Or install it yourself as:
91
91
  |[TbpgrUtils Integer#each_digit](#integereach_digit) |provide iterator for number's each digit |
92
92
  |[TbpgrUtils Integer#each_digit_with_index](#integereach_digit_with_index) |provide iterator for number's each digit with index |
93
93
  |[TbpgrUtils Integer#palindromic_prime?](#integerpalindromic_prime) |Returns true if value is palindromic prime, false for a composite. |
94
+ |[TbpgrUtils Integer#reverse_each_digit](#integerreverse_each_digit) |provide reverse iterator for number's each digit |
94
95
  |[TbpgrUtils Kernel booleans](#kerne-booleans) |True or False instance aliases. |
95
96
  |[TbpgrUtils Kernel#bulk_define_methods](#kernelbulk_define_methods) |define methods to classes. methods have simple return value. |
96
97
  |[TestToolbox Kernel#capture_stdout](#kernelcapture_stdout) |capture STDOUT |
@@ -1583,6 +1584,16 @@ require 'tbpgr_utils'
1583
1584
 
1584
1585
  [back to list](#list)
1585
1586
 
1587
+ ### Integer#reverse_each_digit
1588
+ ~~~ruby
1589
+ require 'tbpgr_utils'
1590
+ ret=[];
1591
+ 12345.reverse_each_digit { |v|ret << v + 1 };
1592
+ print ret # => [6, 5, 4, 3, 2]
1593
+ ~~~
1594
+
1595
+ [back to list](#list)
1596
+
1586
1597
  ### Kernel booleans
1587
1598
  ~~~ruby
1588
1599
  require 'tbpgr_utils'
@@ -3791,6 +3802,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3791
3802
  https://github.com/tbpgr/tbpgr_utils_snippets
3792
3803
 
3793
3804
  ## History
3805
+ * version 0.0.134 : add Integer#reverse_each_digit
3794
3806
  * version 0.0.133 : add Integer#each_digit_with_index
3795
3807
  * version 0.0.132 : add Integer#each_digit
3796
3808
  * version 0.0.131 : add Object#grep_protected_instance_method, Object#grep_private_instance_method
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ class Integer
4
+ # provide reverse iterator for number's each digit
5
+ #
6
+ # === Example
7
+ #
8
+ # ret=[];12345.reverse_each_digit { |v|ret << v+1 };print ret # => [6, 5, 4, 3, 2]
9
+ #
10
+ def reverse_each_digit
11
+ abs.to_s.split('').reverse.map { |v|v.to_i }.each { |v|yield(v) }
12
+ end
13
+ end
@@ -2,3 +2,4 @@
2
2
  require 'open_classes/integer/each_digit'
3
3
  require 'open_classes/integer/each_digit_with_index'
4
4
  require 'open_classes/integer/palindromic_prime'
5
+ require 'open_classes/integer/reverse_each_digit'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.133'
5
+ VERSION = '0.0.134'
6
6
  end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'open_classes/integer/reverse_each_digit'
4
+
5
+ describe Integer do
6
+ context :reverse_each_digit do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'valid case',
11
+ input: 12_345,
12
+ expected: [6, 5, 4, 3, 2],
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].reverse_each_digit { |v|actual << v + 1 }
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.133
4
+ version: 0.0.134
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-20 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -180,6 +180,7 @@ files:
180
180
  - lib/open_classes/integer/each_digit.rb
181
181
  - lib/open_classes/integer/each_digit_with_index.rb
182
182
  - lib/open_classes/integer/palindromic_prime.rb
183
+ - lib/open_classes/integer/reverse_each_digit.rb
183
184
  - lib/open_classes/kernel.rb
184
185
  - lib/open_classes/kernel/aa_ancestors.rb
185
186
  - lib/open_classes/kernel/booleans.rb
@@ -322,6 +323,7 @@ files:
322
323
  - spec/open_classes/integer/each_digit_spec.rb
323
324
  - spec/open_classes/integer/each_digit_with_index_spec.rb
324
325
  - spec/open_classes/integer/palindromic_prime_spec.rb
326
+ - spec/open_classes/integer/reverse_each_digit_spec.rb
325
327
  - spec/open_classes/kernel/aa_ancestors_spec.rb
326
328
  - spec/open_classes/kernel/booleans_spec.rb
327
329
  - spec/open_classes/kernel/bulk_define_methods_spec.rb
@@ -484,6 +486,7 @@ test_files:
484
486
  - spec/open_classes/integer/each_digit_spec.rb
485
487
  - spec/open_classes/integer/each_digit_with_index_spec.rb
486
488
  - spec/open_classes/integer/palindromic_prime_spec.rb
489
+ - spec/open_classes/integer/reverse_each_digit_spec.rb
487
490
  - spec/open_classes/kernel/aa_ancestors_spec.rb
488
491
  - spec/open_classes/kernel/booleans_spec.rb
489
492
  - spec/open_classes/kernel/bulk_define_methods_spec.rb