shouhizei 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +21 -8
- data/lib/shouhizei/version.rb +1 -1
- data/lib/shouhizei.rb +9 -6
- data/shouhizei.gemspec +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 956b51041964291612fcbb8c6fce883e914bfae1
|
4
|
+
data.tar.gz: 0e653a547ea97cad03a37e77916c4d345edbbea7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cedc4d254384d7bbd9eac6d033e8a544c5a94c78e3f805b3d3fe8055c7230e0aae8f2edf696327c7d1e06b70b38b2d52cb3afd58978b644c9b653ade91568b
|
7
|
+
data.tar.gz: 178615794c7a9cad2d80d6d8e6e03d6c145e47a92d2d0f956a43f8d0ec98588725c3365a1b8d812d0ce97fe83be31bad8fae4271d6b1b5b7ae2ea49a491672e9
|
data/README.md
CHANGED
@@ -23,26 +23,39 @@ Or install it yourself as:
|
|
23
23
|
You can get Japanese consumption tax rate like below.
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
Shouhizei.rate_on(
|
26
|
+
Shouhizei.rate_on(Time.zone.local(1989, 3, 31))
|
27
27
|
=> (0/1)
|
28
28
|
|
29
|
-
Shouhizei.rate_on(
|
29
|
+
Shouhizei.rate_on(Time.zone.local(1989, 4, 1))
|
30
30
|
=> (3/100)
|
31
31
|
|
32
|
-
Shouhizei.rate_on(
|
32
|
+
Shouhizei.rate_on(Time.zone.local(1997, 4, 1))
|
33
33
|
=> (1/20)
|
34
34
|
|
35
|
-
Shouhizei.rate_on(
|
35
|
+
Shouhizei.rate_on(Time.zone.local(2014, 4, 1))
|
36
36
|
=> (2/25)
|
37
37
|
|
38
|
-
Shouhizei.rate_on
|
38
|
+
Shouhizei.rate_on # Returns the current consumption tax
|
39
39
|
=> (2/25)
|
40
40
|
```
|
41
41
|
|
42
|
+
This considers local timezone and changes to `'Asia/Tokyo'` by using `ActiveSupport::TimeWithZone#in_time_zone` .
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
> Time.zone = 'Asia/Tokyo'
|
46
|
+
=> "Asia/Tokyo"
|
47
|
+
> Shouhizei.rate_on(Time.zone.local(1989, 3, 31, 10, 0, 0))
|
48
|
+
=> (0/1)
|
49
|
+
> Time.zone = 'Hawaii'
|
50
|
+
=> "Hawaii"
|
51
|
+
> Shouhizei.rate_on(Time.zone.local(1989, 3, 31, 10, 0, 0)) # 1989-04-01 05:00:00 in Japan
|
52
|
+
=> (3/100)
|
53
|
+
```
|
54
|
+
|
42
55
|
Calculation tax included price.
|
43
56
|
Return value class is Integer.
|
44
57
|
```ruby
|
45
|
-
Shouhizei.
|
58
|
+
Shouhizei.including(price: 100, date: Time.zone.local(2014, 4, 1))
|
46
59
|
=> 108 # return value class is Integer
|
47
60
|
```
|
48
61
|
|
@@ -50,11 +63,11 @@ Configuration how to deal fraction round up or round down.
|
|
50
63
|
Default is round down.
|
51
64
|
```ruby
|
52
65
|
Shouhizei.config[:rounding] = Shouhizei::RoundUp
|
53
|
-
Shouhizei.
|
66
|
+
Shouhizei.including(price: 10)
|
54
67
|
=> 11
|
55
68
|
|
56
69
|
Shouhizei.config[:rounding] = Shouhizei::RoundDown
|
57
|
-
Shouhizei.
|
70
|
+
Shouhizei.including(price: 10)
|
58
71
|
=> 10
|
59
72
|
```
|
60
73
|
|
data/lib/shouhizei/version.rb
CHANGED
data/lib/shouhizei.rb
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
require 'shouhizei/version'
|
2
2
|
require 'yaml'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
3
5
|
|
4
6
|
module Shouhizei
|
5
7
|
RoundUp = 'Up'
|
6
8
|
RoundDown = 'Down'
|
7
9
|
|
8
|
-
def self.rate_on(
|
10
|
+
def self.rate_on(time = Time.current)
|
11
|
+
date = time.in_time_zone('Asia/Tokyo').to_date
|
9
12
|
rate_list.reverse_each do |key_date, rate|
|
10
13
|
return rate.to_r if date >= key_date
|
11
14
|
end
|
12
15
|
0.0r
|
13
16
|
end
|
14
17
|
|
15
|
-
def self.
|
16
|
-
|
17
|
-
return
|
18
|
-
|
18
|
+
def self.including(price:, time: Time.current)
|
19
|
+
including_price = price + price * rate_on(time)
|
20
|
+
return including_price.ceil if config[:rounding] == RoundUp
|
21
|
+
including_price.floor
|
19
22
|
end
|
20
23
|
|
21
24
|
def self.config
|
22
|
-
@@config ||= {
|
25
|
+
@@config ||= {rounding: RoundDown}
|
23
26
|
end
|
24
27
|
|
25
28
|
private
|
data/shouhizei.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shouhizei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- colorbox
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08
|
11
|
+
date: 2017-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.1.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.1.0
|
69
83
|
description: This gem support to calculate Japan consumption tax
|
70
84
|
email:
|
71
85
|
- colorbox222@gmail.com
|