round_50sen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73489ae1ce6f39156400c540430c7121198a1d31
4
+ data.tar.gz: 823bf1f03661914575cc6efb5e092a7e868dd25d
5
+ SHA512:
6
+ metadata.gz: 9ddc38874e7b41b12adad87e69f6b07945a0e27e77e660be24970e9031122b5fab2d6687e4b45424f4a2a1a9b1fb848e051e63e73c2f21a23c111c31991e959b
7
+ data.tar.gz: 85dd3b3f37ee302c99f5a9dfd78987dfc9f183120bc3f6d96fd00952e716488e94c3eda24215ed42d25a2584d31d4d55043728e1656bf5079837ad5957a677f9
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.sw*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in round_50sen.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Round50sen
2
+
3
+ 50銭以下を切り捨て、50銭より多い場合は切り上げる`round_50method`を、Integer/Float/BigDecimalに生やすgemです
4
+
5
+ [厚生労働省:雇用保険の一般保険料額表の廃止と被保険者負担額の算定について](http://www.mhlw.go.jp/topics/2005/04/tp0425-2.html)
6
+
7
+ >50銭以下の場合は切り捨て、50銭1厘以上の場合は切り上げとなります。
8
+
9
+ ```rb
10
+ [1] pry(main)> 0.50.round_50sen
11
+ => 0
12
+ [2] pry(main)> 0.51.round_50sen
13
+ => 1
14
+ [3] pry(main)> 0.round_50sen
15
+ => 0
16
+ [4] pry(main)> 1.round_50sen
17
+ => 1
18
+ [6] pry(main)> BigDecimal('0.50000000000000000000000000000000000000').round_50sen.to_f
19
+ => 0.0
20
+ [7] pry(main)> BigDecimal('0.50000000000000000000000000000000000001').round_50sen.to_f
21
+ => 1.0
22
+ [8] pry(main)> BigDecimal('0.5550000000000000000000000000000000000000').round_50sen(2).to_f
23
+ => 0.55
24
+ [9] pry(main)> BigDecimal('0.5550000000000000000000000000000000000001').round_50sen(2).to_f
25
+ => 0.56
26
+ [10] pry(main)> BigDecimal('15000.00000000000000000000000000000000000000').round_50sen(-4).to_f
27
+ => 10000.0
28
+ [11] pry(main)> BigDecimal('15000.00000000000000000000000000000000000001').round_50sen(-4).to_f
29
+ => 20000.0
30
+ ```
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'round_50sen'
38
+ ```
39
+
40
+ And then execute:
41
+
42
+ $ bundle
43
+
44
+ Or install it yourself as:
45
+
46
+ $ gem install round_50sen
47
+
48
+ ## Usage
49
+
50
+ TODO: Write usage instructions here
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( https://github.com/[my-github-username]/round_50sen/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,11 @@
1
+ require 'bigdecimal'
2
+ class BigDecimal
3
+ def round_50sen(n = 0)
4
+ digits = n >= 0 ? '0.1' : '10'
5
+ adjuster = BigDecimal('0.5') * BigDecimal(digits) ** n.abs
6
+
7
+ return (self - adjuster).ceil(n) if self >= 0
8
+
9
+ (self + adjuster).floor(n)
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class Float
2
+ def round_50sen
3
+ return (self - 0.5).ceil if self >= 0
4
+
5
+ (self + 0.5).floor
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def round_50sen
3
+ self
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Round50sen
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "round_50sen/version"
2
+ require 'round_50sen/core_ext/integer'
3
+ require 'round_50sen/core_ext/float'
4
+ require 'round_50sen/core_ext/bigdecimal'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'round_50sen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "round_50sen"
8
+ spec.version = Round50sen::VERSION
9
+ spec.authors = ["ryoff"]
10
+ spec.email = ["ryoffes@gmail.com"]
11
+ spec.summary = %q{round off to 0.50 JPY}
12
+ spec.description = %q{round off to 0.50 JPY}
13
+ spec.homepage = "https://github.com/ryoff/round_50sen"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'bigdecimal'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec-parameterized"
28
+ end
@@ -0,0 +1,156 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe "#round_50sen " do
5
+ describe Integer do
6
+ where(:integer, :rounded) do
7
+ [
8
+ [0, 0],
9
+ [1, 1],
10
+ [-1, -1],
11
+ [99, 99],
12
+ ]
13
+ end
14
+
15
+ with_them do
16
+ subject { integer.round_50sen }
17
+
18
+ it { is_expected.to eq rounded }
19
+ end
20
+ end
21
+
22
+ describe Float do
23
+ where(:float, :rounded) do
24
+ [
25
+ [0.50, 0],
26
+ [0.51, 1],
27
+ [1.49, 1],
28
+ [1.50, 1],
29
+ [1.51, 2],
30
+ [1.50000000, 1],
31
+ [1.50000001, 2],
32
+ [-0.50, -0],
33
+ [-0.51, -1],
34
+ [-1.49, -1],
35
+ [-1.50, -1],
36
+ [-1.51, -2],
37
+ [-1.50000000, -1],
38
+ [-1.50000001, -2],
39
+ ]
40
+ end
41
+
42
+ with_them do
43
+ subject { float.round_50sen }
44
+
45
+ it { is_expected.to eq rounded }
46
+ end
47
+ end
48
+
49
+ describe BigDecimal do
50
+ context 'without args' do
51
+ where(:big_decimal, :rounded) do
52
+ [
53
+ [BigDecimal('0.50'), 0],
54
+ [BigDecimal('0.51'), 1],
55
+ [BigDecimal('1.49'), 1],
56
+ [BigDecimal('1.50'), 1],
57
+ [BigDecimal('1.51'), 2],
58
+ [BigDecimal('1.50000000'), 1],
59
+ [BigDecimal('1.50000001'), 2],
60
+ [BigDecimal('1.50000000000000000000000000000000000000'), 1],
61
+ [BigDecimal('1.50000000000000000000000000000000000001'), 2],
62
+ [BigDecimal('-0.50'), -0],
63
+ [BigDecimal('-0.51'), -1],
64
+ [BigDecimal('-1.49'), -1],
65
+ [BigDecimal('-1.50'), -1],
66
+ [BigDecimal('-1.51'), -2],
67
+ [BigDecimal('-1.5000000000000000000000000000000000000'), -1],
68
+ [BigDecimal('-1.5000000000000000000000000000000000001'), -2],
69
+ ]
70
+ end
71
+
72
+ with_them do
73
+ subject { big_decimal.round_50sen }
74
+
75
+ it { is_expected.to eq rounded }
76
+ end
77
+ end
78
+
79
+ context 'with args is 4' do
80
+ where(:big_decimal, :rounded) do
81
+ [
82
+ [BigDecimal('0.50'), 0.5],
83
+ [BigDecimal('0.51'), 0.51],
84
+ [BigDecimal('1.49'), 1.49],
85
+ [BigDecimal('1.50'), 1.5],
86
+ [BigDecimal('1.51'), 1.51],
87
+ [BigDecimal('1.50000000'), 1.5],
88
+ [BigDecimal('1.50000001'), 1.5],
89
+ [BigDecimal('1.55555000'), 1.5555],
90
+ [BigDecimal('1.55555001'), 1.5556],
91
+ [BigDecimal('1.55555000000000000000000000000000000000'), 1.5555],
92
+ [BigDecimal('1.55555000000000000000000000000000000001'), 1.5556],
93
+ [BigDecimal('-0.50'), -0.5],
94
+ [BigDecimal('-0.51'), -0.51],
95
+ [BigDecimal('-1.49'), -1.49],
96
+ [BigDecimal('-1.50'), -1.50],
97
+ [BigDecimal('-1.51'), -1.51],
98
+ [BigDecimal('-1.55555000'), -1.5555],
99
+ [BigDecimal('-1.55555001'), -1.5556],
100
+ [BigDecimal('-1.55555000000000000000000000000000000000'), -1.5555],
101
+ [BigDecimal('-1.55555000000000000000000000000000000001'), -1.5556],
102
+ ]
103
+ end
104
+
105
+ with_them do
106
+ subject { big_decimal.round_50sen(4) }
107
+
108
+ it { is_expected.to eq rounded }
109
+ end
110
+ end
111
+
112
+ context 'with args is minus 1' do
113
+ where(:big_decimal, :rounded) do
114
+ [
115
+ [BigDecimal('0.50'), 0],
116
+ [BigDecimal('15.0'), 10],
117
+ [BigDecimal('15.1'), 20],
118
+ [BigDecimal('15.000000000000000000000000000000000'), 10],
119
+ [BigDecimal('15.000000000000000000000000000000001'), 20],
120
+ [BigDecimal('-15.0'), -10],
121
+ [BigDecimal('-15.1'), -20],
122
+ [BigDecimal('-15.000000000000000000000000000000000'), -10],
123
+ [BigDecimal('-15.000000000000000000000000000000001'), -20],
124
+ ]
125
+ end
126
+
127
+ with_them do
128
+ subject { big_decimal.round_50sen(-1) }
129
+
130
+ it { is_expected.to eq rounded }
131
+ end
132
+ end
133
+
134
+ context 'with args is minus 4' do
135
+ where(:big_decimal, :rounded) do
136
+ [
137
+ [BigDecimal('0.50'), 0],
138
+ [BigDecimal('15000.0'), 10000],
139
+ [BigDecimal('15000.1'), 20000],
140
+ [BigDecimal('15000.000000000000000000000000000000000'), 10000],
141
+ [BigDecimal('15000.000000000000000000000000000000001'), 20000],
142
+ [BigDecimal('-15000.0'), -10000],
143
+ [BigDecimal('-15000.1'), -20000],
144
+ [BigDecimal('-15000.000000000000000000000000000000000'), -10000],
145
+ [BigDecimal('-15000.000000000000000000000000000000001'), -20000],
146
+ ]
147
+ end
148
+
149
+ with_them do
150
+ subject { big_decimal.round_50sen(-4) }
151
+
152
+ it { is_expected.to eq rounded }
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'round_50sen'
3
+ require 'rspec-parameterized'
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: round_50sen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ryoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bigdecimal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-parameterized
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: round off to 0.50 JPY
98
+ email:
99
+ - ryoffes@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/round_50sen.rb
110
+ - lib/round_50sen/core_ext/bigdecimal.rb
111
+ - lib/round_50sen/core_ext/float.rb
112
+ - lib/round_50sen/core_ext/integer.rb
113
+ - lib/round_50sen/version.rb
114
+ - round_50sen.gemspec
115
+ - spec/round_50sen_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: https://github.com/ryoff/round_50sen
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: round off to 0.50 JPY
141
+ test_files:
142
+ - spec/round_50sen_spec.rb
143
+ - spec/spec_helper.rb