kiriban_getter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f175c9778c4d415bc6e65f68f3d246a90079ca58
4
+ data.tar.gz: 0df242bdcc0d2b52133939dbf0923e67915e042c
5
+ SHA512:
6
+ metadata.gz: 5e79dc49c190173cb4818e6a602197bc0636de7d346c0b63a11ca0e935c53991b84655a309a8d63dfa132d4282c5389fe4dbf66e53e3078fe199664e12cbf7b6
7
+ data.tar.gz: f6ca22ff74594d28a2265fc0d4d404329a3dccf7629d10f8f1980d103c69deb64e992428b66a007a332b1b14ffcfbfcaa24fefee15015e8f4deefb5635b7e67a
@@ -0,0 +1 @@
1
+ repo_token: 5bDnStGSeW2NiY3nVjI7rD3ZmtwXh4TxH
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,23 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3.1
7
+ - ruby-head
8
+ before_install: gem install bundler -v 1.12.3
9
+ cache: bundler
10
+ before_script:
11
+ - export CODECLIMATE_REPO_TOKEN=8f450c1a3ba1c7589d8bf7d937f53e540f23e2c875650a61fc36f1e6682a5ab4
12
+ - export CI=true
13
+ script:
14
+ - bundle exec rspec
15
+ branches:
16
+ only:
17
+ - master
18
+ notifications:
19
+ slack:
20
+ secure: jYJBCIqtreEfU6aleufyqnI6xWDfJjFXJEOXqVq0xtxOPVb1F4nQvYfV1pHCJYlVZxHqQ015xKFHYXY28XEKh4EcfIEQ7H++2oGACxEaf8bxiiIVm3U8TAazAq9SuvXR4DCy1hnYlpvIQX6J2GX7cefgrgdm0VTGUtzxSHA119CWbTJHxVjJPL9W+o2GpfFYTMD6BEZo8FrRfEvTmrpEoumjQPLd5v35ScOL2ROnjUeW/uwL4WcmfRvo0VZveDWlMGXebWzCknpPIp2n3rj3BWFHf4JPs+WQZxFUv11aihrAyGicRS48H8nJ8sFzLNnerom9X995vRnsHQXabjwDby58YLMoLxB1ypnH1lvm6EH3ctIiVWXHYr1CgziY+pDe0A+rjsCF6SjTp9sMi6tAwnrkPbfjAhT4A55cBjpVoSVl9tp9jd3g1PErbOWpaaHFsKH0VHjfhhMhqBNVkeOQ8F8gAwSbyIYFgQzS8xPJicYP/MlAvyHcCbrR7pxmVFmba5oVF8cY4thahEB6QmjOdioD+2y6JbE30G/+Slpzu0FE9B0Vc7HSRHFDQeckzAGzZuU+Gzie3xxEdzTaqrqdU2wQu+GnQ4KMVp9UY4BjNvDcS5M2AqfTdUxvG6IC4ChUUSfkLKuyG1AWQytxjfVTFx4GHc/Pvtta55JtZ+NE1pY=
21
+ matrix:
22
+ allow_failures:
23
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kiriban_getter.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 sue445
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,104 @@
1
+ # KiribanGetter
2
+ Check number whether **Kiriban (キリ番)**
3
+
4
+ Add `#kiriban_getter?`, `#kuraiban?` and `#zorome?` methods to `Integer`
5
+
6
+ [![Build Status](https://travis-ci.org/sue445/zatsu_monitor.svg?branch=master)](https://travis-ci.org/sue445/zatsu_monitor)
7
+ [![Code Climate](https://codeclimate.com/github/sue445/kiriban_getter/badges/gpa.svg)](https://codeclimate.com/github/sue445/kiriban_getter)
8
+ [![Coverage Status](https://coveralls.io/repos/github/sue445/kiriban_getter/badge.svg?branch=master)](https://coveralls.io/github/sue445/kiriban_getter?branch=master)
9
+ [![Dependency Status](https://gemnasium.com/badges/github.com/sue445/kiriban_getter.svg)](https://gemnasium.com/github.com/sue445/kiriban_getter)
10
+
11
+ ## Requirements
12
+ * Ruby 2.1+
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'kiriban_getter'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install kiriban_getter
29
+
30
+ ## Usage
31
+ ```ruby
32
+ require "kiriban_getter"
33
+
34
+ using KiribanGetter
35
+ ```
36
+
37
+ ### #kiriban? (キリ番?)
38
+ `#kiriban?` is `#kuraiban?` or `#zorome?`
39
+
40
+ ```ruby
41
+ 100.kiriban?
42
+ #=> true
43
+
44
+ 101.kiriban?
45
+ #=> false
46
+
47
+ 111.kiriban?
48
+ #=> true
49
+ ```
50
+
51
+ ### #kuraiban? (位番?)
52
+ ```ruby
53
+ 100.kuraiban?
54
+ #=> true
55
+
56
+ 101.kuraiban?
57
+ #=> false
58
+
59
+ 111.kuraiban?
60
+ #=> false
61
+
62
+ 2000.kuraiban?
63
+ #=> true
64
+ ```
65
+
66
+ Also aliased as: `#zeroban?`
67
+
68
+
69
+ ### #zorome? (ゾロ目?)
70
+ ```ruby
71
+ 111.zorome?
72
+ #=> true
73
+
74
+ 2222.zorome?
75
+ #=> true
76
+
77
+ 2223.zorome?
78
+ #=> false
79
+ ```
80
+
81
+ Also aliased as: `#repdigit?`, `#monodigit?`
82
+
83
+ ## Development
84
+
85
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
86
+
87
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
88
+
89
+ ## Benchmark
90
+ run [benchmark/kiriban_getter.rb](benchmark/kiriban_getter.rb)
91
+
92
+ ```sh
93
+ bundle exec ruby benchmark/kiriban_getter.rb
94
+ ```
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/kiriban_getter.
99
+
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
104
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,87 @@
1
+ require "benchmark/ips"
2
+
3
+ def rand_num
4
+ rand(1000000)
5
+ end
6
+
7
+ module KiribanBenchmark
8
+ refine Integer do
9
+ def digit_1
10
+ digit = 1
11
+
12
+ num = self.abs
13
+ while num >= 10
14
+ digit += 1
15
+ num /= 10
16
+ end
17
+
18
+ digit
19
+ end
20
+
21
+ def digit_2
22
+ self.abs.to_s.length
23
+ end
24
+
25
+ alias_method :digit, :digit_2
26
+
27
+ def kuraiban_1?
28
+ !!(self.abs.to_s =~ /^[1-9]0+$/)
29
+ end
30
+
31
+ def kuraiban_2?
32
+ num = self.abs
33
+ return false if num < 10
34
+
35
+ i = 10 ** (digit - 1)
36
+ num % i == 0
37
+ end
38
+
39
+ def zorome_1?
40
+ num = self.abs
41
+ return false if num < 10
42
+ num.to_s.each_char.map(&:itself).uniq.count == 1
43
+ end
44
+
45
+ def zorome_2?
46
+ num = self.abs
47
+ return false if num < 10
48
+
49
+ # generate number which all digit is 1
50
+ zorome1 = digit.times.inject(0) { |n| n * 10 + 1 }
51
+ num % zorome1 == 0
52
+ end
53
+ end
54
+ end
55
+
56
+ Benchmark.ips do |x|
57
+ using KiribanBenchmark
58
+
59
+ x.config(time: 5, warmup: 2)
60
+
61
+ x.report("digit_1") { rand_num.digit_1 }
62
+ x.report("digit_2") { rand_num.digit_2 }
63
+
64
+ x.compare!
65
+ end
66
+
67
+ Benchmark.ips do |x|
68
+ using KiribanBenchmark
69
+
70
+ x.config(time: 5, warmup: 2)
71
+
72
+ x.report("kuraiban_1?") { rand_num.kuraiban_1? }
73
+ x.report("kuraiban_2?") { rand_num.kuraiban_2? }
74
+
75
+ x.compare!
76
+ end
77
+
78
+ Benchmark.ips do |x|
79
+ using KiribanBenchmark
80
+
81
+ x.config(time: 5, warmup: 2)
82
+
83
+ x.report("zorome_1?") { rand_num.zorome_1? }
84
+ x.report("zorome_2?") { rand_num.zorome_2? }
85
+
86
+ x.compare!
87
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kiriban"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kiriban_getter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kiriban_getter"
8
+ spec.version = KiribanGetter::VERSION
9
+ spec.authors = ["sue445"]
10
+ spec.email = ["sue445@sue445.net"]
11
+
12
+ spec.summary = %q{Check number whether kiriban}
13
+ spec.description = %q{Check number whether kiriban}
14
+ spec.homepage = "https://github.com/sue445/kiriban_getter"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = ">= 2.1.0"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "benchmark-ips"
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "codeclimate-test-reporter"
27
+ spec.add_development_dependency "coveralls"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "rspec-parameterized"
31
+ end
@@ -0,0 +1,34 @@
1
+ require "kiriban_getter/version"
2
+
3
+ module KiribanGetter
4
+ refine Integer do
5
+ def kuraiban?
6
+ num = self.abs
7
+ return false if num < 10
8
+
9
+ i = 10 ** (digit - 1)
10
+ num % i == 0
11
+ end
12
+ alias_method :zeroban?, :kuraiban?
13
+
14
+ def zorome?
15
+ num = self.abs
16
+ return false if num < 10
17
+
18
+ # generate number which all digit is 1
19
+ zorome1 = digit.times.inject(0) { |n| n * 10 + 1 }
20
+ num % zorome1 == 0
21
+ end
22
+
23
+ alias_method :repdigit?, :zorome?
24
+ alias_method :monodigit?, :zorome?
25
+
26
+ def digit
27
+ self.abs.to_s.length
28
+ end
29
+
30
+ def kiriban?
31
+ kuraiban? || zorome?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module KiribanGetter
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiriban_getter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: benchmark-ips
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-parameterized
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Check number whether kiriban
112
+ email:
113
+ - sue445@sue445.net
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".coveralls.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - benchmark/kiriban_getter.rb
127
+ - bin/console
128
+ - bin/setup
129
+ - kiriban_getter.gemspec
130
+ - lib/kiriban_getter.rb
131
+ - lib/kiriban_getter/version.rb
132
+ homepage: https://github.com/sue445/kiriban_getter
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.1.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.5.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Check number whether kiriban
156
+ test_files: []