From cc47cff65f1d6eacd54f6525d9c6f97cf1026138 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Sun, 31 Dec 2017 16:25:15 +0000 Subject: [PATCH] Release 1.0.0 --- gem/.rubocop.yml | 2 +- gem/Gemfile.lock | 37 +++++++++++++++---------------- gem/README.md | 8 ++++++- gem/Rakefile | 2 +- gem/fixer.gemspec | 12 +++++----- gem/lib/fixer.rb | 14 ++++++++++++ gem/lib/fixer/feed.rb | 8 +++---- gem/lib/fixer/version.rb | 2 +- gem/spec/{ => fixer}/feed_spec.rb | 12 +++++----- gem/spec/fixer_spec.rb | 34 ++++++++++++++++++++++++++++ 10 files changed, 92 insertions(+), 39 deletions(-) rename gem/spec/{ => fixer}/feed_spec.rb (81%) create mode 100644 gem/spec/fixer_spec.rb diff --git a/gem/.rubocop.yml b/gem/.rubocop.yml index ce8eb67..2762899 100644 --- a/gem/.rubocop.yml +++ b/gem/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 Metrics/BlockLength: Exclude: - 'spec/**/*' diff --git a/gem/Gemfile.lock b/gem/Gemfile.lock index f1da239..81ddf79 100644 --- a/gem/Gemfile.lock +++ b/gem/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - fixer (0.7.0) + fixer (1.0.0) GEM remote: https://rubygems.org/ @@ -13,26 +13,25 @@ GEM safe_yaml (~> 1.0.0) hashdiff (0.3.7) minitest (5.10.3) - parallel (1.12.0) - parser (2.4.0.0) - ast (~> 2.2) + parallel (1.12.1) + parser (2.4.0.2) + ast (~> 2.3) powerpack (0.1.1) - public_suffix (3.0.0) - rainbow (2.2.2) - rake - rake (10.5.0) - rubocop (0.51.0) + public_suffix (3.0.1) + rainbow (3.0.0) + rake (12.3.0) + rubocop (0.52.1) parallel (~> 1.10) - parser (>= 2.3.3.1, < 3.0) + parser (>= 2.4.0.2, < 3.0) powerpack (~> 0.1) - rainbow (>= 2.2.2, < 3.0) + rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.9.0) safe_yaml (1.0.4) unicode-display_width (1.3.0) - vcr (3.0.3) - webmock (2.3.2) + vcr (4.0.0) + webmock (3.1.1) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff @@ -41,13 +40,13 @@ PLATFORMS ruby DEPENDENCIES - bundler (~> 1.0) + bundler fixer! - minitest (~> 5.0) - rake (~> 10.0) + minitest + rake rubocop - vcr (~> 3.0) - webmock (~> 2.3) + vcr + webmock BUNDLED WITH - 1.16.0 + 1.16.1 diff --git a/gem/README.md b/gem/README.md index 05187d4..1e80d3e 100644 --- a/gem/README.md +++ b/gem/README.md @@ -1,3 +1,9 @@ # Fixer -Fixer wraps the XML feeds of Euro foreign exchange reference provided by the European Central Bank. +Fixer wraps the XML feeds of Euro foreign exchange reference provided by the European Central Bank: + +```ruby +Fixer.current +Fixer.ninety_days +Fixer.historical +``` diff --git a/gem/Rakefile b/gem/Rakefile index 1ab4946..4bfab90 100644 --- a/gem/Rakefile +++ b/gem/Rakefile @@ -6,7 +6,7 @@ require 'rubocop/rake_task' Rake::TestTask.new do |t| t.ruby_opts += ['-W1'] - t.pattern = 'spec/*_spec.rb' + t.pattern = 'spec/**/*_spec.rb' end RuboCop::RakeTask.new diff --git a/gem/fixer.gemspec b/gem/fixer.gemspec index 2ded906..8409483 100644 --- a/gem/fixer.gemspec +++ b/gem/fixer.gemspec @@ -14,13 +14,13 @@ Gem::Specification.new do |spec| SUMMARY spec.homepage = 'https://github.com/hakanensari/fixer' spec.license = 'MIT' - spec.files = Dir.glob('lib/**/*') + %w[LICENSE README.md] + spec.files = Dir.glob('lib/**/*') + %w[README.md] spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 1.0' - spec.add_development_dependency 'minitest', '~> 5.0' - spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'bundler' + spec.add_development_dependency 'minitest' + spec.add_development_dependency 'rake' spec.add_development_dependency 'rubocop' - spec.add_development_dependency 'vcr', '~> 3.0' - spec.add_development_dependency 'webmock', '~> 2.3' + spec.add_development_dependency 'vcr' + spec.add_development_dependency 'webmock' end diff --git a/gem/lib/fixer.rb b/gem/lib/fixer.rb index 13a418b..0ef8edd 100644 --- a/gem/lib/fixer.rb +++ b/gem/lib/fixer.rb @@ -1,3 +1,17 @@ # frozen_string_literal: true require 'fixer/feed' + +# ECB exchange rate datasets +# +# The three available short hands here are `.current`, `.ninety_days`, and +# `.historical`. +module Fixer + class << self + Feed::SCOPES.each_key do |scope| + define_method(scope) do + Feed.new(scope) + end + end + end +end diff --git a/gem/lib/fixer/feed.rb b/gem/lib/fixer/feed.rb index 37692c7..2abc474 100644 --- a/gem/lib/fixer/feed.rb +++ b/gem/lib/fixer/feed.rb @@ -8,14 +8,14 @@ module Fixer class Feed include Enumerable - TYPES = { + SCOPES = { current: 'daily', ninety_days: 'hist-90d', historical: 'hist' }.freeze - def initialize(type = :current) - @type = TYPES.fetch(type) { raise ArgumentError } + def initialize(scope = :current) + @scope = SCOPES.fetch(scope) { raise ArgumentError } end def each @@ -42,7 +42,7 @@ module Fixer end def url - URI("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-#{@type}.xml") + URI("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-#{@scope}.xml") end end end diff --git a/gem/lib/fixer/version.rb b/gem/lib/fixer/version.rb index 2a8a7a5..3a84b82 100644 --- a/gem/lib/fixer/version.rb +++ b/gem/lib/fixer/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Fixer - VERSION = '0.7.0' + VERSION = '1.0.0' end diff --git a/gem/spec/feed_spec.rb b/gem/spec/fixer/feed_spec.rb similarity index 81% rename from gem/spec/feed_spec.rb rename to gem/spec/fixer/feed_spec.rb index 74b7d82..cf32765 100644 --- a/gem/spec/feed_spec.rb +++ b/gem/spec/fixer/feed_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'helper' +require_relative '../helper' module Fixer describe Feed do @@ -8,25 +8,25 @@ module Fixer after { VCR.eject_cassette } it 'parses the date of a currency' do - feed = Feed.new + feed = Feed.new(:current) currency = feed.first currency[:date].must_be_kind_of Date end it 'parse the ISO code of a currency' do - feed = Feed.new + feed = Feed.new(:current) currency = feed.first currency[:iso_code].must_be_kind_of String end it 'parses the rate of a currency' do - feed = Feed.new + feed = Feed.new(:current) currency = feed.first currency[:rate].must_be_kind_of Float end it 'fetches current rates' do - feed = Feed.new + feed = Feed.new(:current) feed.count.must_be :<, 40 end @@ -40,7 +40,7 @@ module Fixer feed.count.must_be :>, 33 * 3000 end - it 'raises error with invalid type' do + it 'raises error when scope is not valid' do -> { Feed.new(:invalid) }.must_raise ArgumentError end end diff --git a/gem/spec/fixer_spec.rb b/gem/spec/fixer_spec.rb new file mode 100644 index 0000000..f70df12 --- /dev/null +++ b/gem/spec/fixer_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require_relative 'helper' + +describe Fixer do + before do + @mock = MiniTest::Mock.new + end + + after do + @mock.verify + end + + it 'returns current rates' do + @mock.expect(:call, nil, [:current]) + Fixer::Feed.stub(:new, @mock) do + Fixer.current + end + end + + it 'returns ninety-day rates' do + @mock.expect(:call, nil, [:ninety_days]) + Fixer::Feed.stub(:new, @mock) do + Fixer.ninety_days + end + end + + it 'returns historical rates' do + @mock.expect(:call, nil, [:historical]) + Fixer::Feed.stub(:new, @mock) do + Fixer.historical + end + end +end