tbpgr_utils 0.0.102 → 0.0.103

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -82,6 +82,7 @@ Or install it yourself as:
82
82
  |[Ghostable module](#ghostable) |help to create ghost method(dynamic method define by ussing method_missing + pattern-method-name) |
83
83
  |[TbpgrUtils Hash#html_table](#hashhtml_table) |get html table string from key + value |
84
84
  |[TbpgrUtils Hash#table](#hashtable) |get pipe format table string from key + value |
85
+ |[TbpgrUtils Integer#palindromic_prime?](#integerpalindromic_prime) |Returns true if value is palindromic prime, false for a composite. |
85
86
  |[TbpgrUtils Kernel booleans](#kerne-booleans) |True or False instance aliases. |
86
87
  |[TbpgrUtils Kernel#bulk_define_methods](#kernelbulk_define_methods) |define methods to classes. methods have simple return value. |
87
88
  |[TestToolbox Kernel#capture_stdout](#kernelcapture_stdout) |capture STDOUT |
@@ -1476,6 +1477,19 @@ result
1476
1477
 
1477
1478
  [back to list](#list)
1478
1479
 
1480
+ ### Integer#palindromic_prime
1481
+ ~~~ruby
1482
+ require 'tbpgr_utils'
1483
+ 0.palindromic_prime? # => false
1484
+ 1.palindromic_prime? # => false
1485
+ 2.palindromic_prime? # => true
1486
+ 11.palindromic_prime? # => true
1487
+ 757.palindromic_prime? # => true
1488
+ 758.palindromic_prime? # => false
1489
+ ~~~
1490
+
1491
+ [back to list](#list)
1492
+
1479
1493
  ### Kernel booleans
1480
1494
  ~~~ruby
1481
1495
  require 'tbpgr_utils'
@@ -3282,6 +3296,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3282
3296
  https://github.com/tbpgr/tbpgr_utils_snippets
3283
3297
 
3284
3298
  ## History
3299
+ * version 0.0.103 : add Integer#palindromic_prime
3285
3300
  * version 0.0.102 : add String#cygwinpath_to_winpath
3286
3301
  * version 0.0.101 : add String#winpath_to_cygwinpath
3287
3302
  * version 0.0.100 : add String#ascii_unicode_html_table
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'prime'
3
+
4
+ class Integer
5
+ # Returns true if value is palindromic prime, false for a composite.
6
+ #
7
+ # === Example
8
+ #
9
+ # 0.palindromic_prime? # => false
10
+ # 1.palindromic_prime? # => false
11
+ # 2.palindromic_prime? # => true
12
+ # 11.palindromic_prime? # => true
13
+ # 757.palindromic_prime? # => true
14
+ # 758.palindromic_prime? # => false
15
+ #
16
+ def palindromic_prime?
17
+ prime? && to_s == to_s.reverse
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'open_classes/integer/palindromic_prime'
@@ -8,9 +8,9 @@ class String
8
8
  # '/cygdrive/c/hoge/hoge.txt'.cygwinpath_to_winpath # => 'C:\hoge\hoge.txt'
9
9
  #
10
10
  def cygwinpath_to_winpath
11
- return self unless match(/\/cygdrive\//)
12
- drive = scan(/\/cygdrive\/(\w)\//).first.first.upcase
13
- dir_file = scan(/\/cygdrive\/\w\/(.*)/).first.first.gsub('/', '\\')
11
+ return self unless match(%r{/cygdrive/})
12
+ drive = scan(%r{/cygdrive/(\w)/}).first.first.upcase
13
+ dir_file = scan(%r{/cygdrive/\w/(.*)}).first.first.gsub('/', '\\')
14
14
  "#{drive}:\\#{dir_file}"
15
15
  end
16
16
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.102'
5
+ VERSION = '0.0.103'
6
6
  end
data/lib/tbpgr_utils.rb CHANGED
@@ -7,6 +7,7 @@ module TbpgrUtils
7
7
  require 'open_classes/file'
8
8
  require 'open_classes/fixnum'
9
9
  require 'open_classes/hash'
10
+ require 'open_classes/integer'
10
11
  require 'open_classes/kernel'
11
12
  require 'open_classes/module'
12
13
  require 'open_classes/numeric'
@@ -11,7 +11,7 @@ describe Familyable::Family do
11
11
  persons: [
12
12
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
13
13
  b = Familyable::Person.new(id: 2, parent_ids: []),
14
- c = Familyable::Person.new(id: 3, parent_ids: [4], ),
14
+ c = Familyable::Person.new(id: 3, parent_ids: [4]),
15
15
  d = Familyable::Person.new(id: 4, parent_ids: []),
16
16
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
17
17
  ],
@@ -59,7 +59,7 @@ describe Familyable::Family do
59
59
  persons: [
60
60
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
61
61
  b = Familyable::Person.new(id: 2, parent_ids: []),
62
- c = Familyable::Person.new(id: 3, parent_ids: [4], ),
62
+ c = Familyable::Person.new(id: 3, parent_ids: [4]),
63
63
  d = Familyable::Person.new(id: 4, parent_ids: []),
64
64
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
65
65
  ],
@@ -107,7 +107,7 @@ describe Familyable::Family do
107
107
  persons: [
108
108
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
109
109
  b = Familyable::Person.new(id: 2, parent_ids: []),
110
- c = Familyable::Person.new(id: 3, parent_ids: [4], ),
110
+ c = Familyable::Person.new(id: 3, parent_ids: [4]),
111
111
  d = Familyable::Person.new(id: 4, parent_ids: [3]),
112
112
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
113
113
  ],
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'open_classes/integer/palindromic_prime'
4
+
5
+ describe Integer do
6
+ context :palindromic_prime? do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: '0 case',
11
+ input: 0,
12
+ expected: false,
13
+ },
14
+ {
15
+ case_no: 2,
16
+ case_title: '1 case',
17
+ input: 1,
18
+ expected: false,
19
+ },
20
+ {
21
+ case_no: 3,
22
+ case_title: 'palindromic_primes case(2)',
23
+ input: 2,
24
+ expected: true,
25
+ },
26
+ {
27
+ case_no: 4,
28
+ case_title: 'palindromic_primes case(757)',
29
+ input: 757,
30
+ expected: true,
31
+ },
32
+ {
33
+ case_no: 5,
34
+ case_title: 'not palindromic_primes case(758)',
35
+ input: 758,
36
+ expected: false,
37
+ },
38
+ ]
39
+
40
+ cases.each do |c|
41
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
42
+ begin
43
+ case_before c
44
+
45
+ # -- given --
46
+ # nothing
47
+
48
+ # -- when --
49
+ actual = c[:input].palindromic_prime?
50
+
51
+ # -- then --
52
+ expect(actual).to eq(c[:expected])
53
+ ensure
54
+ case_after c
55
+ end
56
+ end
57
+
58
+ def case_before(c)
59
+ # implement each case before
60
+ end
61
+
62
+ def case_after(c)
63
+ # implement each case after
64
+ end
65
+ end
66
+ end
67
+ 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.102
4
+ version: 0.0.103
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-04-19 00:00:00.000000000 Z
12
+ date: 2014-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &21059076 !ruby/object:Gem::Requirement
16
+ requirement: &26225532 !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: *21059076
24
+ version_requirements: *26225532
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &21057996 !ruby/object:Gem::Requirement
27
+ requirement: &26224980 !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: *21057996
35
+ version_requirements: *26224980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &21073368 !ruby/object:Gem::Requirement
38
+ requirement: &26224572 !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: *21073368
46
+ version_requirements: *26224572
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &21072288 !ruby/object:Gem::Requirement
49
+ requirement: &26223756 !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: *21072288
57
+ version_requirements: *26223756
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &21071328 !ruby/object:Gem::Requirement
60
+ requirement: &26223312 !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: *21071328
68
+ version_requirements: *26223312
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -145,6 +145,8 @@ files:
145
145
  - lib/open_classes/hash.rb
146
146
  - lib/open_classes/hash/html_table.rb
147
147
  - lib/open_classes/hash/table.rb
148
+ - lib/open_classes/integer.rb
149
+ - lib/open_classes/integer/palindromic_prime.rb
148
150
  - lib/open_classes/kernel.rb
149
151
  - lib/open_classes/kernel/aa_ancestors.rb
150
152
  - lib/open_classes/kernel/booleans.rb
@@ -261,6 +263,7 @@ files:
261
263
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
262
264
  - spec/open_classes/hash/html_table_spec.rb
263
265
  - spec/open_classes/hash/table_spec.rb
266
+ - spec/open_classes/integer/palindromic_prime_spec.rb
264
267
  - spec/open_classes/kernel/aa_ancestors_spec.rb
265
268
  - spec/open_classes/kernel/booleans_spec.rb
266
269
  - spec/open_classes/kernel/bulk_define_methods_spec.rb
@@ -398,6 +401,7 @@ test_files:
398
401
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
399
402
  - spec/open_classes/hash/html_table_spec.rb
400
403
  - spec/open_classes/hash/table_spec.rb
404
+ - spec/open_classes/integer/palindromic_prime_spec.rb
401
405
  - spec/open_classes/kernel/aa_ancestors_spec.rb
402
406
  - spec/open_classes/kernel/booleans_spec.rb
403
407
  - spec/open_classes/kernel/bulk_define_methods_spec.rb