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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac4ad367008d491b345bb08edfc30cd294399f5b
4
- data.tar.gz: 69bb81259a1563cac37436c0c38c82e4e846d8ac
3
+ metadata.gz: 956b51041964291612fcbb8c6fce883e914bfae1
4
+ data.tar.gz: 0e653a547ea97cad03a37e77916c4d345edbbea7
5
5
  SHA512:
6
- metadata.gz: 8bf4726182b9f071ce10846ff5bacdde118fd802ec2286a264735e7162dfa60926de966d0b0348714b2cbbf30354b09f9059ca4aaf94d9c9353817ccea7004e0
7
- data.tar.gz: c498cb34567dc64bf99b30eec11f037d933b83b10edae97bf4a26809fac661f04e25194f35bb889db8dfcea28bcc1d4445febb950b8eca7b352cb052ca31778d
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(Date.new(1989, 3, 31))
26
+ Shouhizei.rate_on(Time.zone.local(1989, 3, 31))
27
27
  => (0/1)
28
28
 
29
- Shouhizei.rate_on(Date.new(1989, 4, 1))
29
+ Shouhizei.rate_on(Time.zone.local(1989, 4, 1))
30
30
  => (3/100)
31
31
 
32
- Shouhizei.rate_on(Date.new(1997, 4, 1))
32
+ Shouhizei.rate_on(Time.zone.local(1997, 4, 1))
33
33
  => (1/20)
34
34
 
35
- Shouhizei.rate_on(Date.new(2014, 4, 1))
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.included(price: 100, date: Date.new(2014, 4, 1))
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.included(price: 10)
66
+ Shouhizei.including(price: 10)
54
67
  => 11
55
68
 
56
69
  Shouhizei.config[:rounding] = Shouhizei::RoundDown
57
- Shouhizei.included(price: 10)
70
+ Shouhizei.including(price: 10)
58
71
  => 10
59
72
  ```
60
73
 
@@ -1,3 +1,3 @@
1
1
  module Shouhizei
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
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(date = Date.today)
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.included(price:, date: Date.today)
16
- included_price = price + price * rate_on(date)
17
- return included_price.ceil if config[:rounding] == RoundUp
18
- included_price.floor
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 ||= {ronding: RoundDown}
25
+ @@config ||= {rounding: RoundDown}
23
26
  end
24
27
 
25
28
  private
data/shouhizei.gemspec CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "minitest", "~> 5.0"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "timecop", "~> 0.9"
26
+
27
+ spec.add_dependency "activesupport", ">= 4.1.0"
26
28
  end
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.1.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-27 00:00:00.000000000 Z
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