Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ on:

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
ruby-version: ["3.1", "3.2", "3.3", "3.4"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
Expand Down
11 changes: 9 additions & 2 deletions eu_central_bank.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ Gem::Specification.new do |s|
s.description = "This gem reads exchange rates from the european central bank website. It uses it to calculates exchange rates. It is compatible with the money gem"
s.license = "MIT"

s.add_dependency "nokogiri", RUBY_VERSION >= "2.1" ? "~> 1.9" : "~> 1.6.8"
s.add_dependency "money", "~> 6.13", ">= 6.13.6"
s.metadata['changelog_uri'] = "https://github.com/RubyMoney/eu_central_bank/blob/main/CHANGELOG.md"
s.metadata['source_code_uri'] = "https://github.com/RubyMoney/eu_central_bank"
s.metadata['bug_tracker_uri'] = "https://github.com/RubyMoney/eu_central_bank/issues"

s.required_ruby_version = ">= 3.1.0"

s.add_dependency "bigdecimal"
s.add_dependency "nokogiri", "~> 1.11"
s.add_dependency "money", "~> 6.19"

s.add_development_dependency "rspec", "~> 3.12.0"

Expand Down
16 changes: 4 additions & 12 deletions lib/eu_central_bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def update_historical_rates(cache=nil, all=false)
def save_rates(cache, url=ECB_RATES_URL)
raise InvalidCache unless cache
File.open(cache, "w") do |file|
io = open_url(url)
io = URI.open(url)
io.each_line { |line| file.puts line }
end
end
Expand All @@ -56,7 +56,7 @@ def update_rates_from_s(content)
end

def save_rates_to_s(url=ECB_RATES_URL)
open_url(url).read
URI.open(url).read
end

def exchange(cents, from_currency, to_currency, date=nil)
Expand Down Expand Up @@ -179,9 +179,9 @@ def check_currency_available(currency)
def doc(cache, url=ECB_RATES_URL)
rates_source = !!cache ? cache : url
begin
parse_rates(open_url(rates_source))
parse_rates(URI.open(rates_source))
rescue Nokogiri::XML::XPath::SyntaxError
parse_rates(open_url(url))
parse_rates(URI.open(url))
end
end

Expand Down Expand Up @@ -237,12 +237,4 @@ def calculate_exchange(from, to_currency, rate)
money = (decimal_money * from.cents * rate).round
Money.new(money, to_currency)
end

def open_url(url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:chefkiss:

if RUBY_VERSION >= '2.5.0'
URI.open(url)
else
open(url)
end
end
end