seven_bank_fx_rate 1.0.0 → 1.1.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/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/seven_bank_fx_rate/parser.rb +8 -8
- data/lib/seven_bank_fx_rate/seven_bank_fx_rate.rb +8 -3
- data/lib/seven_bank_fx_rate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77c756f13108334c7a5afd0e9e686231de1a2207e7b60ba1be0329bed55901f1
|
4
|
+
data.tar.gz: 76b1401a985dbae61ef7672f36c6b92d6a0efad978ba409a09a6fff2f47550d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf490eb059fa8b5138fd685cb516c0e95653c40336f134758fe2c66921ac4e1486a56ad6cd6ebd509933025d1009a35bf9f0cb8261054397dd52b4c89957dbe
|
7
|
+
data.tar.gz: 55783b2ff0e8b397c0b358222d69bff04308589197f8657eb87cb611e0b358626d346b489d92f3370205086e66265a27bc81edc102cba819e1dc079cf9204bc9
|
data/CHANGELOG.md
CHANGED
@@ -1,2 +1,7 @@
|
|
1
1
|
### v1.0.0
|
2
2
|
- Initial release
|
3
|
+
|
4
|
+
### v1.1.0
|
5
|
+
- Switched unnecessary instance variables in `SevenBankFxRate::Parser` to local ones
|
6
|
+
- Fixed `SevenBankFxRate::respond_to_missing` to strictly check missing method pattern
|
7
|
+
- Added mutex to avoid extra http requests due to race condition with multiple threads
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SevenBankFxRate
|
1
|
+
# SevenBankFxRate [](https://badge.fury.io/rb/seven_bank_fx_rate) [](https://travis-ci.org/yuan-jiang/seven_bank_fx_rate)
|
2
2
|
|
3
3
|
Easier access to the foreign exchange rate data of Seven Bank international
|
4
4
|
money transfer service in Japan, with JPY1.00 as the base currency and unit.
|
@@ -8,27 +8,27 @@ module SevenBankFxRate
|
|
8
8
|
# @param response the body of Net::HTTPResponse
|
9
9
|
def initialize(response)
|
10
10
|
@root = REXML::Document.new(response).root
|
11
|
-
@meta = Elements::Meta.new
|
12
|
-
@countries = []
|
13
11
|
end
|
14
12
|
|
15
13
|
# Parses the <header> section in original xml response
|
16
14
|
# @return instance of SevenBankFxRate::Elements::Meta
|
17
15
|
def meta
|
18
|
-
|
16
|
+
meta = Elements::Meta.new
|
17
|
+
return meta unless @root
|
19
18
|
|
20
19
|
%w[create_date apply_date apply_time data_count].each do |attr|
|
21
20
|
@root.elements.each("header/#{attr.split('_').join}") do |e|
|
22
|
-
|
21
|
+
meta.send("#{attr}=".to_sym, e.text.strip)
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
24
|
+
meta
|
26
25
|
end
|
27
26
|
|
28
27
|
# Parses the <countries> section in original xml response
|
29
28
|
# @return an array of SevenBankFxRate::Elements::Country
|
30
29
|
def countries
|
31
|
-
|
30
|
+
countries = []
|
31
|
+
return countries unless @root
|
32
32
|
|
33
33
|
@root.elements.each('countries/country') do |country_tag|
|
34
34
|
country = Elements::Country.new
|
@@ -38,9 +38,9 @@ module SevenBankFxRate
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
country.currencies = currencies country_tag
|
41
|
-
|
41
|
+
countries << country
|
42
42
|
end
|
43
|
-
|
43
|
+
countries
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SevenBankFxRate
|
4
|
+
@mutex = Mutex.new
|
4
5
|
class << self
|
5
6
|
# Methods to access meta attributes of the latest exchange rate data
|
6
7
|
%i[create_date apply_date apply_time data_count].each do |attr|
|
@@ -47,11 +48,15 @@ module SevenBankFxRate
|
|
47
48
|
private
|
48
49
|
|
49
50
|
def data
|
50
|
-
@
|
51
|
+
@mutex.synchronize do
|
52
|
+
@data ||= Data.new
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
56
|
+
GHOST_METHOD_PATTERN = /\Acountry_[A-Za-z]{2}_currency_[A-Za-z]{3}\z/.freeze
|
57
|
+
|
53
58
|
def method_missing(method_name, *arguments, &block)
|
54
|
-
if
|
59
|
+
if GHOST_METHOD_PATTERN =~ method_name.to_s
|
55
60
|
_, country_code, _, currency_code = method_name.to_s.split('_')
|
56
61
|
send :for, country_code, currency_code
|
57
62
|
else
|
@@ -60,7 +65,7 @@ module SevenBankFxRate
|
|
60
65
|
end
|
61
66
|
|
62
67
|
def respond_to_missing?(method_name, include_private = false)
|
63
|
-
method_name.to_s
|
68
|
+
!!(GHOST_METHOD_PATTERN =~ method_name.to_s) || super
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seven_bank_fx_rate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jiang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|