seven_bank_fx_rate 1.0.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/seven_bank_fx_rate.rb +50 -0
- data/lib/seven_bank_fx_rate/agent.rb +25 -0
- data/lib/seven_bank_fx_rate/elements/country.rb +24 -0
- data/lib/seven_bank_fx_rate/elements/currency.rb +15 -0
- data/lib/seven_bank_fx_rate/elements/meta.rb +16 -0
- data/lib/seven_bank_fx_rate/parser.rb +64 -0
- data/lib/seven_bank_fx_rate/seven_bank_fx_rate.rb +78 -0
- data/lib/seven_bank_fx_rate/version.rb +5 -0
- data/seven_bank_fx_rate.gemspec +32 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27785e430ec8ad56d4f8a8e15eb1b549a5a0158596e50ad44f31feff6cf9b7d1
|
4
|
+
data.tar.gz: c68def2502e4a0d4155d4e6c787acafc4d871b12cc1ea6f07678d6a151e5dfa3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9470dda92c3bcd91e129b6d6f826eb92395296360551207ef939eff9bcb95526734e7fc55b10aa173ef4e415f6f924aab0913885029d21aa9900c7a275b7a46
|
7
|
+
data.tar.gz: 074d973f412d82ac61eb5b1d103ba827824bfb66ddcd744a048487af74afb3430b78e4594b56537b3d4cc1e773216257ad856be792d43dcbd2f904a89ab21151
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at andy.jiang@appier.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Andy Jiang
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# SevenBankFxRate
|
2
|
+
|
3
|
+
Easier access to the foreign exchange rate data of Seven Bank international
|
4
|
+
money transfer service in Japan, with JPY1.00 as the base currency and unit.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'seven_bank_fx_rate'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install seven_bank_fx_rate
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
- Require the module
|
25
|
+
```ruby
|
26
|
+
require 'seven_bank_fx_rate'
|
27
|
+
```
|
28
|
+
|
29
|
+
- Get meta information:
|
30
|
+
```ruby
|
31
|
+
SevenBankFxRate.create_date
|
32
|
+
SevenBankFxRate.apply_date
|
33
|
+
SevenBankFxRate.apply_time
|
34
|
+
SevenBankFxRate.data_count
|
35
|
+
```
|
36
|
+
|
37
|
+
- Get exchange rate with specific country code and currency code:
|
38
|
+
```ruby
|
39
|
+
# methods:
|
40
|
+
SevenBankFxRate.for :xx, :yyy
|
41
|
+
SevenBankFxRate.find 'xx', 'yyy'
|
42
|
+
SevenBankFxRate.country_xx_currency_yyy
|
43
|
+
|
44
|
+
# examples:
|
45
|
+
SevenBankFxRate.for :cn, :cny
|
46
|
+
SevenBankFxRate.for 'cn', 'usd'
|
47
|
+
SevenBankFxRate.for :cn, :CNY
|
48
|
+
SevenBankFxRate.for :CN, :usd
|
49
|
+
SevenBankFxRate.find :cn, :cny
|
50
|
+
SevenBankFxRate.find 'cn', 'usd'
|
51
|
+
SevenBankFxRate.country_cn_currency_cny
|
52
|
+
SevenBankFxRate.country_CN_currency_USD
|
53
|
+
|
54
|
+
# notes:
|
55
|
+
# * xx standards for country code and yyy standards for currency code
|
56
|
+
# * both symbol and string formats can be used for either code
|
57
|
+
# * both country code and currency code are case insensitive
|
58
|
+
# * country code reference: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
59
|
+
# * currency code reference: https://en.wikipedia.org/wiki/ISO_4217
|
60
|
+
```
|
61
|
+
|
62
|
+
- Get an array of exchange rate for all available countries and currencies:
|
63
|
+
```ruby
|
64
|
+
SevenBankFxRate.all
|
65
|
+
```
|
66
|
+
|
67
|
+
- Forcibly update latest data:
|
68
|
+
```ruby
|
69
|
+
SevenBankFxRate.update!
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
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.
|
75
|
+
|
76
|
+
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).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yuan-jiang/seven_bank_fx_rate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yuan-jiang/seven_bank_fx_rate/blob/master/CODE_OF_CONDUCT.md).
|
81
|
+
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
86
|
+
|
87
|
+
## Code of Conduct
|
88
|
+
|
89
|
+
Everyone interacting in the SevenBankFxRate project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yuan-jiang/seven_bank_fx_rate/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'seven_bank_fx_rate'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Easier access to the foreign exchange rate data of Seven Bank international
|
4
|
+
# money transfer service in Japan, with JPY1.00 as the base currency and unit.
|
5
|
+
#
|
6
|
+
# Example of usage:
|
7
|
+
#
|
8
|
+
# - Get meta information:
|
9
|
+
# SevenBankFxRate.create_date
|
10
|
+
# SevenBankFxRate.apply_date
|
11
|
+
# SevenBankFxRate.apply_time
|
12
|
+
# SevenBankFxRate.data_count
|
13
|
+
#
|
14
|
+
# - Get exchange rate with specific country code and currency code:
|
15
|
+
# Method patterns:
|
16
|
+
# SevenBankFxRate.for :xx, :yyy
|
17
|
+
# SevenBankFxRate.find 'xx', 'yyy'
|
18
|
+
# SevenBankFxRate.country_xx_currency_yyy
|
19
|
+
# where xx is country code and yyy is currency code; both symbol and
|
20
|
+
# string can be used for either code with case-insensitive formats:
|
21
|
+
# e.g.
|
22
|
+
# SevenBankFxRate.for :cn, :cny
|
23
|
+
# SevenBankFxRate.for 'cn', 'usd'
|
24
|
+
# SevenBankFxRate.for :cn, :CNY
|
25
|
+
# SevenBankFxRate.for :CN, :usd
|
26
|
+
# SevenBankFxRate.find :cn, :cny
|
27
|
+
# SevenBankFxRate.find 'cn', 'usd'
|
28
|
+
# SevenBankFxRate.country_cn_currency_cny
|
29
|
+
# SevenBankFxRate.country_CN_currency_USD
|
30
|
+
#
|
31
|
+
# Country codes reference:
|
32
|
+
# https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
33
|
+
# Currency codes reference:
|
34
|
+
# https://en.wikipedia.org/wiki/ISO_4217
|
35
|
+
#
|
36
|
+
# - Get an array of exchange rate for all available countries and currencies:
|
37
|
+
# SevenBankFxRate.all
|
38
|
+
#
|
39
|
+
# - Forcibly update latest data:
|
40
|
+
# SevenBankFxRate.update!
|
41
|
+
#
|
42
|
+
module SevenBankFxRate
|
43
|
+
require 'seven_bank_fx_rate/version'
|
44
|
+
require 'seven_bank_fx_rate/agent'
|
45
|
+
require 'seven_bank_fx_rate/parser'
|
46
|
+
require 'seven_bank_fx_rate/elements/meta'
|
47
|
+
require 'seven_bank_fx_rate/elements/country'
|
48
|
+
require 'seven_bank_fx_rate/elements/currency'
|
49
|
+
require 'seven_bank_fx_rate/seven_bank_fx_rate'
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module SevenBankFxRate
|
6
|
+
SOURCE_URL = 'https://www.sevenbank.co.jp/t/html/file/CurrentFXList.xml'
|
7
|
+
|
8
|
+
# Sends http request to fetch the latest exchange rate data
|
9
|
+
class Agent
|
10
|
+
# Fetches the latest data as Net::HTTPResponse object
|
11
|
+
# @return the body of Net::HTTPResponse
|
12
|
+
#
|
13
|
+
# @raise errors if response code is not '200', or any network failure
|
14
|
+
def self.response
|
15
|
+
puts "Sending http request to: #{SOURCE_URL}" if $DEBUG
|
16
|
+
response = Net::HTTP.get_response URI.parse(SOURCE_URL)
|
17
|
+
unless response.code == '200'
|
18
|
+
puts response.body if $DEBUG
|
19
|
+
raise StandardError,
|
20
|
+
"Unexpected response from fetching latest data: #{response.code}"
|
21
|
+
end
|
22
|
+
response.body
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SevenBankFxRate
|
4
|
+
module Elements
|
5
|
+
# Corresponds to the country tag in xml:
|
6
|
+
# <country>
|
7
|
+
# <countrycode>CN</countrycode>
|
8
|
+
# <countryname>China</countryname>
|
9
|
+
# <currency>
|
10
|
+
# <currencycode>CNY</currencycode>
|
11
|
+
# <currencyname>Chinese Yuan Renminbi</currencyname>
|
12
|
+
# <fxrate>0.0636548</fxrate>
|
13
|
+
# </currency>
|
14
|
+
# <currency>
|
15
|
+
# <currencycode>USD</currencycode>
|
16
|
+
# <currencyname>US Dollar</currencyname>
|
17
|
+
# <fxrate>0.0093211</fxrate>
|
18
|
+
# </currency>
|
19
|
+
# </country>
|
20
|
+
class Country
|
21
|
+
attr_accessor :country_code, :country_name, :currencies
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SevenBankFxRate
|
4
|
+
module Elements
|
5
|
+
# Corresponds to the currency tag in xml:
|
6
|
+
# <currency>
|
7
|
+
# <currencycode>USD</currencycode>
|
8
|
+
# <currencyname>US Dollar</currencyname>
|
9
|
+
# <fxrate>0.0090386</fxrate>
|
10
|
+
# </currency>
|
11
|
+
class Currency
|
12
|
+
attr_accessor :currency_code, :currency_name, :fx_rate
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SevenBankFxRate
|
4
|
+
module Elements
|
5
|
+
# Corresponds to the header tag in xml:
|
6
|
+
# <header>
|
7
|
+
# <createdate>20200903</createdate>
|
8
|
+
# <applydate>20200903</applydate>
|
9
|
+
# <applytime>0800</applytime>
|
10
|
+
# <datacount>0288</datacount>
|
11
|
+
# </header>
|
12
|
+
class Meta
|
13
|
+
attr_accessor :create_date, :apply_date, :apply_time, :data_count
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
module SevenBankFxRate
|
6
|
+
# Parses xml response content and convert to ruby objects
|
7
|
+
class Parser
|
8
|
+
# @param response the body of Net::HTTPResponse
|
9
|
+
def initialize(response)
|
10
|
+
@root = REXML::Document.new(response).root
|
11
|
+
@meta = Elements::Meta.new
|
12
|
+
@countries = []
|
13
|
+
end
|
14
|
+
|
15
|
+
# Parses the <header> section in original xml response
|
16
|
+
# @return instance of SevenBankFxRate::Elements::Meta
|
17
|
+
def meta
|
18
|
+
return @meta unless @root
|
19
|
+
|
20
|
+
%w[create_date apply_date apply_time data_count].each do |attr|
|
21
|
+
@root.elements.each("header/#{attr.split('_').join}") do |e|
|
22
|
+
@meta.send("#{attr}=".to_sym, e.text.strip)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
@meta
|
26
|
+
end
|
27
|
+
|
28
|
+
# Parses the <countries> section in original xml response
|
29
|
+
# @return an array of SevenBankFxRate::Elements::Country
|
30
|
+
def countries
|
31
|
+
return @countries unless @root
|
32
|
+
|
33
|
+
@root.elements.each('countries/country') do |country_tag|
|
34
|
+
country = Elements::Country.new
|
35
|
+
%w[country_code country_name].each do |attr|
|
36
|
+
country_tag.elements.each(attr.split('_').join) do |e|
|
37
|
+
country.send("#{attr}=".to_sym, e.text.strip)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
country.currencies = currencies country_tag
|
41
|
+
@countries << country
|
42
|
+
end
|
43
|
+
@countries
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Parses the <currencies> section in original xml response
|
49
|
+
# @return an array of SevenBankFxRate::Elements::Currency
|
50
|
+
def currencies(country_tag)
|
51
|
+
currencies = []
|
52
|
+
country_tag.elements.each('currency') do |currency_tag|
|
53
|
+
currency = Elements::Currency.new
|
54
|
+
%w[currency_code currency_name fx_rate].each do |attr|
|
55
|
+
currency_tag.elements.each(attr.split('_').join) do |e|
|
56
|
+
currency.send("#{attr}=".to_sym, e.text.strip)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
currencies << currency
|
60
|
+
end
|
61
|
+
currencies
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SevenBankFxRate
|
4
|
+
class << self
|
5
|
+
# Methods to access meta attributes of the latest exchange rate data
|
6
|
+
%i[create_date apply_date apply_time data_count].each do |attr|
|
7
|
+
define_method attr do
|
8
|
+
data.meta.send attr
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return exchange rate for given country code and currency code or nil
|
13
|
+
#
|
14
|
+
# if either country or currency code is invalid or when there is no
|
15
|
+
# exchange rate data available for the country and currency combination
|
16
|
+
def for(country_code, currency_code)
|
17
|
+
country = all.find do |c|
|
18
|
+
c.country_code == country_code.to_s.upcase
|
19
|
+
end
|
20
|
+
return unless country
|
21
|
+
|
22
|
+
currency = country.currencies.find do |c|
|
23
|
+
c.currency_code == currency_code.to_s.upcase
|
24
|
+
end
|
25
|
+
currency&.fx_rate
|
26
|
+
end
|
27
|
+
|
28
|
+
alias find for
|
29
|
+
|
30
|
+
# @return exchange rate data for all available countries
|
31
|
+
#
|
32
|
+
# as an array of SevenBankFxRate::Elements::Country
|
33
|
+
def all
|
34
|
+
data.countries
|
35
|
+
end
|
36
|
+
|
37
|
+
# Upon accessing of any of the public methods, the exchange rate data are
|
38
|
+
# fetched once and then cached for the lifetime of the module, because the
|
39
|
+
# remote xml source is updated only 3 times a day based on the website.
|
40
|
+
#
|
41
|
+
# However, this method still allows fetching the latest data when needed.
|
42
|
+
def update!
|
43
|
+
@data = Data.new
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def data
|
50
|
+
@data ||= Data.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def method_missing(method_name, *arguments, &block)
|
54
|
+
if /\Acountry_[A-Za-z]{2}_currency_[A-Za-z]{3}\z/ =~ method_name.to_s
|
55
|
+
_, country_code, _, currency_code = method_name.to_s.split('_')
|
56
|
+
send :for, country_code, currency_code
|
57
|
+
else
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def respond_to_missing?(method_name, include_private = false)
|
63
|
+
method_name.to_s.start_with?('country_') || super
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Holds the parsed exchange rate data represented by
|
68
|
+
# ruby objects converted from original xml content
|
69
|
+
class Data
|
70
|
+
attr_reader :meta, :countries
|
71
|
+
|
72
|
+
def initialize
|
73
|
+
parser = Parser.new Agent.response
|
74
|
+
@meta = parser.meta
|
75
|
+
@countries = parser.countries
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/seven_bank_fx_rate/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'seven_bank_fx_rate'
|
7
|
+
spec.version = SevenBankFxRate::VERSION
|
8
|
+
spec.authors = ['Andy Jiang']
|
9
|
+
spec.email = ['yuanjiang@outlook.com']
|
10
|
+
|
11
|
+
spec.summary = 'Easier access to the foreign exchange rate data of Seven Bank international money transfer service in Japan.'
|
12
|
+
spec.homepage = 'https://github.com/yuan-jiang/seven_bank_fx_rate'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
15
|
+
|
16
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/yuan-jiang/seven_bank_fx_rate/blob/master/CHANGELOG.md'
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seven_bank_fx_rate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Jiang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- yuanjiang@outlook.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/seven_bank_fx_rate.rb
|
74
|
+
- lib/seven_bank_fx_rate/agent.rb
|
75
|
+
- lib/seven_bank_fx_rate/elements/country.rb
|
76
|
+
- lib/seven_bank_fx_rate/elements/currency.rb
|
77
|
+
- lib/seven_bank_fx_rate/elements/meta.rb
|
78
|
+
- lib/seven_bank_fx_rate/parser.rb
|
79
|
+
- lib/seven_bank_fx_rate/seven_bank_fx_rate.rb
|
80
|
+
- lib/seven_bank_fx_rate/version.rb
|
81
|
+
- seven_bank_fx_rate.gemspec
|
82
|
+
homepage: https://github.com/yuan-jiang/seven_bank_fx_rate
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
allowed_push_host: https://rubygems.org/
|
87
|
+
homepage_uri: https://github.com/yuan-jiang/seven_bank_fx_rate
|
88
|
+
source_code_uri: https://github.com/yuan-jiang/seven_bank_fx_rate
|
89
|
+
changelog_uri: https://github.com/yuan-jiang/seven_bank_fx_rate/blob/master/CHANGELOG.md
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 2.3.0
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Easier access to the foreign exchange rate data of Seven Bank international
|
109
|
+
money transfer service in Japan.
|
110
|
+
test_files: []
|