kiriban_getter 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f175c9778c4d415bc6e65f68f3d246a90079ca58
4
- data.tar.gz: 0df242bdcc0d2b52133939dbf0923e67915e042c
3
+ metadata.gz: c05033f45c59dc857baaf6d84d59f8b76b7b88ae
4
+ data.tar.gz: f782f09687a1323a6f2e112a25ade58610b9d9c9
5
5
  SHA512:
6
- metadata.gz: 5e79dc49c190173cb4818e6a602197bc0636de7d346c0b63a11ca0e935c53991b84655a309a8d63dfa132d4282c5389fe4dbf66e53e3078fe199664e12cbf7b6
7
- data.tar.gz: f6ca22ff74594d28a2265fc0d4d404329a3dccf7629d10f8f1980d103c69deb64e992428b66a007a332b1b14ffcfbfcaa24fefee15015e8f4deefb5635b7e67a
6
+ metadata.gz: 5da4ba8e0583742f4cd136615b715603cbd08a7d912fc50912d1238beb588a5d64abaeab8a5a39597491debb36f07601483d41d6c6edf1524bb9f0c7e63d7bf6
7
+ data.tar.gz: 18768cbc7988d58a23bab1f5907c02313fc75a3820150abbae3071c77ff71a5e25cf6a965064f5eae45f8087f24785a70f2f7b3dc099d46cd334ac32f67d0408
@@ -0,0 +1,8 @@
1
+ languages:
2
+ Ruby: true
3
+ JavaScript: true
4
+ PHP: true
5
+ Python: true
6
+ exclude_paths:
7
+ - "spec/**/*"
8
+ - "benchmark/kiriban_getter.rb"
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # KiribanGetter
2
2
  Check number whether **Kiriban (キリ番)**
3
3
 
4
- Add `#kiriban_getter?`, `#kuraiban?` and `#zorome?` methods to `Integer`
4
+ Add `#kiriban?`, `#kuraiban?` and `#zorome?` methods to `Integer`
5
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/kiriban_getter.svg)](https://badge.fury.io/rb/kiriban_getter)
6
7
  [![Build Status](https://travis-ci.org/sue445/zatsu_monitor.svg?branch=master)](https://travis-ci.org/sue445/zatsu_monitor)
7
8
  [![Code Climate](https://codeclimate.com/github/sue445/kiriban_getter/badges/gpa.svg)](https://codeclimate.com/github/sue445/kiriban_getter)
8
9
  [![Coverage Status](https://coveralls.io/repos/github/sue445/kiriban_getter/badge.svg?branch=master)](https://coveralls.io/github/sue445/kiriban_getter?branch=master)
@@ -1,11 +1,12 @@
1
1
  require "benchmark/ips"
2
2
 
3
3
  def rand_num
4
- rand(1000000)
4
+ rand(-10_000_000..10_000_000)
5
5
  end
6
6
 
7
7
  module KiribanBenchmark
8
8
  refine Integer do
9
+ # legacy
9
10
  def digit_1
10
11
  digit = 1
11
12
 
@@ -18,16 +19,33 @@ module KiribanBenchmark
18
19
  digit
19
20
  end
20
21
 
22
+ # v0.1.0
21
23
  def digit_2
22
24
  self.abs.to_s.length
23
25
  end
24
26
 
25
- alias_method :digit, :digit_2
27
+ def digit_3
28
+ return 1 if self.zero?
29
+ Math.log10(self.abs).to_i + 1
30
+ end
31
+
32
+ # v0.1.1
33
+ def digit_4
34
+ Math.log10(self.abs).to_i + 1
35
+ rescue FloatDomainError
36
+ # Math.log10(0).to_i
37
+ # #=> FloatDomainError: -Infinity
38
+ 1
39
+ end
26
40
 
41
+ alias_method :digit, :digit_4
42
+
43
+ # legacy
27
44
  def kuraiban_1?
28
45
  !!(self.abs.to_s =~ /^[1-9]0+$/)
29
46
  end
30
47
 
48
+ # v0.1.0
31
49
  def kuraiban_2?
32
50
  num = self.abs
33
51
  return false if num < 10
@@ -36,12 +54,14 @@ module KiribanBenchmark
36
54
  num % i == 0
37
55
  end
38
56
 
57
+ # legacy
39
58
  def zorome_1?
40
59
  num = self.abs
41
60
  return false if num < 10
42
61
  num.to_s.each_char.map(&:itself).uniq.count == 1
43
62
  end
44
63
 
64
+ # v0.1.0
45
65
  def zorome_2?
46
66
  num = self.abs
47
67
  return false if num < 10
@@ -50,6 +70,21 @@ module KiribanBenchmark
50
70
  zorome1 = digit.times.inject(0) { |n| n * 10 + 1 }
51
71
  num % zorome1 == 0
52
72
  end
73
+
74
+ # via.
75
+ # * https://github.com/osyo-manga/gem-kiriban/blob/v0.1.0/lib/kiriban/core.rb,
76
+ # * https://github.com/osyo-manga/gem-kiriban/blob/v0.1.0/lib/kiriban/core_ext.rb
77
+ def to_kiriban_array
78
+ to_s.split(//)
79
+ end
80
+
81
+ def zeroban? top = 1
82
+ to_kiriban_array.drop(top).all?{ |it| it.to_i == 0 }
83
+ end
84
+
85
+ def zoroban?
86
+ to_kiriban_array.uniq.size == 1
87
+ end
53
88
  end
54
89
  end
55
90
 
@@ -58,8 +93,10 @@ Benchmark.ips do |x|
58
93
 
59
94
  x.config(time: 5, warmup: 2)
60
95
 
61
- x.report("digit_1") { rand_num.digit_1 }
62
- x.report("digit_2") { rand_num.digit_2 }
96
+ x.report("digit_1 (legacy)") { rand_num.digit_1 }
97
+ x.report("digit_2 (v0.1.0)") { rand_num.digit_2 }
98
+ x.report("digit_3") { rand_num.digit_3 }
99
+ x.report("digit_4 (v0.1.1)") { rand_num.digit_4 }
63
100
 
64
101
  x.compare!
65
102
  end
@@ -69,8 +106,9 @@ Benchmark.ips do |x|
69
106
 
70
107
  x.config(time: 5, warmup: 2)
71
108
 
72
- x.report("kuraiban_1?") { rand_num.kuraiban_1? }
73
- x.report("kuraiban_2?") { rand_num.kuraiban_2? }
109
+ x.report("kuraiban_1? (legacy)") { rand_num.kuraiban_1? }
110
+ x.report("kuraiban_2? (v0.1.0)") { rand_num.kuraiban_2? }
111
+ x.report("zeroban? (kiriban gem)") { rand_num.zeroban? }
74
112
 
75
113
  x.compare!
76
114
  end
@@ -80,8 +118,9 @@ Benchmark.ips do |x|
80
118
 
81
119
  x.config(time: 5, warmup: 2)
82
120
 
83
- x.report("zorome_1?") { rand_num.zorome_1? }
84
- x.report("zorome_2?") { rand_num.zorome_2? }
121
+ x.report("zorome_1? (legacy)") { rand_num.zorome_1? }
122
+ x.report("zorome_2? (v0.1.0)") { rand_num.zorome_2? }
123
+ x.report("zoroban? (kiriban gem)") { rand_num.zoroban? }
85
124
 
86
125
  x.compare!
87
126
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "kiriban"
4
+ require "kiriban_getter"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -24,7 +24,11 @@ module KiribanGetter
24
24
  alias_method :monodigit?, :zorome?
25
25
 
26
26
  def digit
27
- self.abs.to_s.length
27
+ Math.log10(self.abs).to_i + 1
28
+ rescue FloatDomainError
29
+ # Math.log10(0).to_i
30
+ # #=> FloatDomainError: -Infinity
31
+ 1
28
32
  end
29
33
 
30
34
  def kiriban?
@@ -1,3 +1,3 @@
1
1
  module KiribanGetter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiriban_getter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-25 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".codeclimate.yml"
118
119
  - ".coveralls.yml"
119
120
  - ".gitignore"
120
121
  - ".rspec"