tbpgr_utils 0.0.131 → 0.0.132
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/open_classes/integer/each_digit.rb +13 -0
- data/lib/open_classes/integer.rb +3 -2
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/open_classes/integer/each_digit_spec.rb +44 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa077187bcfddd3a88184d5d807f7edf64fd0bb6
|
4
|
+
data.tar.gz: 5f826256f5d4b1dfb81a28309d5b122fa709edf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d7d644a0b83a1e3c68154bf66f37b21fccaa4e8ebca087aaad9237057924bd7693019679e6328cd723fd93ecc46dd7576d8f986dbd19fc2e5e169897f1e3811
|
7
|
+
data.tar.gz: 49afb39e2da60d6a40b3193d5dfee19e050bf59fbf598e573bf00b30a00c0885915b1b15b5f66291e31063bc0ff9e1e8249f604d34dba5b9c5af0b8fd1770288
|
data/README.md
CHANGED
@@ -88,6 +88,7 @@ Or install it yourself as:
|
|
88
88
|
|[TbpgrUtils Hash#>>](#hash) |return HashContext for each execute |
|
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
|
+
|[TbpgrUtils Integer#each_digit](#integereach_digit) |provide iterator for number's each digit |
|
91
92
|
|[TbpgrUtils Integer#palindromic_prime?](#integerpalindromic_prime) |Returns true if value is palindromic prime, false for a composite. |
|
92
93
|
|[TbpgrUtils Kernel booleans](#kerne-booleans) |True or False instance aliases. |
|
93
94
|
|[TbpgrUtils Kernel#bulk_define_methods](#kernelbulk_define_methods) |define methods to classes. methods have simple return value. |
|
@@ -1548,6 +1549,16 @@ result
|
|
1548
1549
|
|
1549
1550
|
[back to list](#list)
|
1550
1551
|
|
1552
|
+
### Integer#each_digit
|
1553
|
+
~~~ruby
|
1554
|
+
require 'tbpgr_utils'
|
1555
|
+
ret=[];
|
1556
|
+
12345.each_digit { |v|ret << v+1 };
|
1557
|
+
print ret # => [2,3,4,5,6]
|
1558
|
+
~~~
|
1559
|
+
|
1560
|
+
[back to list](#list)
|
1561
|
+
|
1551
1562
|
### Integer#palindromic_prime
|
1552
1563
|
~~~ruby
|
1553
1564
|
require 'tbpgr_utils'
|
@@ -3769,6 +3780,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
3769
3780
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
3770
3781
|
|
3771
3782
|
## History
|
3783
|
+
* version 0.0.132 : add Integer#each_digit
|
3772
3784
|
* version 0.0.131 : add Object#grep_protected_instance_method, Object#grep_private_instance_method
|
3773
3785
|
* version 0.0.130 : add Object#grep_method
|
3774
3786
|
* version 0.0.129 : add Object#grep_public_instance_method
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Integer
|
4
|
+
# provide iterator for number's each digit
|
5
|
+
#
|
6
|
+
# === Example
|
7
|
+
#
|
8
|
+
# ret=[];12345.each_digit { |v|ret << v+1 };print ret # => [2,3,4,5,6]
|
9
|
+
#
|
10
|
+
def each_digit
|
11
|
+
abs.to_s.split('').map { |v|v.to_i }.each { |v|yield(v) }
|
12
|
+
end
|
13
|
+
end
|
data/lib/open_classes/integer.rb
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'open_classes/integer/
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'open_classes/integer/each_digit'
|
3
|
+
require 'open_classes/integer/palindromic_prime'
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'open_classes/integer/each_digit'
|
4
|
+
|
5
|
+
describe Integer do
|
6
|
+
context :each_digit do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: 'valid case',
|
11
|
+
input: 12_345,
|
12
|
+
expected: [2, 3, 4, 5, 6],
|
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 { |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.
|
4
|
+
version: 0.0.132
|
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-
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- lib/open_classes/hash/html_table.rb
|
178
178
|
- lib/open_classes/hash/table.rb
|
179
179
|
- lib/open_classes/integer.rb
|
180
|
+
- lib/open_classes/integer/each_digit.rb
|
180
181
|
- lib/open_classes/integer/palindromic_prime.rb
|
181
182
|
- lib/open_classes/kernel.rb
|
182
183
|
- lib/open_classes/kernel/aa_ancestors.rb
|
@@ -317,6 +318,7 @@ files:
|
|
317
318
|
- spec/open_classes/hash/gte_gte_spec.rb
|
318
319
|
- spec/open_classes/hash/html_table_spec.rb
|
319
320
|
- spec/open_classes/hash/table_spec.rb
|
321
|
+
- spec/open_classes/integer/each_digit_spec.rb
|
320
322
|
- spec/open_classes/integer/palindromic_prime_spec.rb
|
321
323
|
- spec/open_classes/kernel/aa_ancestors_spec.rb
|
322
324
|
- spec/open_classes/kernel/booleans_spec.rb
|
@@ -477,6 +479,7 @@ test_files:
|
|
477
479
|
- spec/open_classes/hash/gte_gte_spec.rb
|
478
480
|
- spec/open_classes/hash/html_table_spec.rb
|
479
481
|
- spec/open_classes/hash/table_spec.rb
|
482
|
+
- spec/open_classes/integer/each_digit_spec.rb
|
480
483
|
- spec/open_classes/integer/palindromic_prime_spec.rb
|
481
484
|
- spec/open_classes/kernel/aa_ancestors_spec.rb
|
482
485
|
- spec/open_classes/kernel/booleans_spec.rb
|