Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Code refactoring #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 5 additions & 0 deletions .cane
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--no-doc
--no-style
--style-measure 99
--abc-max 18
--style-exclude spec/**/*
Copy link
Owner

Choose a reason for hiding this comment

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

What's a .cane file and why should I merge it in with this PR?

Copy link
Author

Choose a reason for hiding this comment

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

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.gem
.bundle
Gemfile.lock
*.lock
pkg/*
doc/*
coverage/*
coverage/*
.idea
4 changes: 3 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
--colour
--color
--format documentation
--require spec_helper
17 changes: 17 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AllCops:
Include:
- '**/Rakefile'
Exclude:
- 'spec/**/*'
Style/LineLength:
Max: 99
Style/FileName:
Enabled: false
Style/ModuleFunction:
Enabled: false
Style/Encoding:
Enabled: false
Documentation:
Enabled: false
Style/MethodLength:
Max: 15
Copy link
Owner

Choose a reason for hiding this comment

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

The Rubocop addition should have probably gone into a separate PR…

However, I guess I can pull it in with this PR regardless… Could you change the config so that the style matches my earlier style in the gem (the main issue being that double quotes are proffered over single quotes).

Copy link
Author

Choose a reason for hiding this comment

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

What the reason of using double quotes over single? Do you know why double quotes is bad?

35 changes: 12 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
script: "bundle exec rake spec"
language: ruby
rvm:
- 1.9.3
- 2.1.1
- 2.0.0
- 2.1
- ruby-head
- jruby-19mode
- rbx
notifications:
disable: true
- rbx-2
gemfile:
- money-5.1.gemfile
- money-6.0.gemfile
- money-head.gemfile
- gemfiles/money_6.1.gemfile
- gemfiles/money_6.2.gemfile
- gemfiles/money_head.gemfile
matrix:
allow_failures:
- gemfile: gemfiles/money-head.gemfile
exclude:
- rvm: 1.9.3
gemfile: money-5.1.gemfile
- rvm: jruby-19mode
gemfile: money-5.1.gemfile
- rvm: rbx
gemfile: money-5.1.gemfile
- rvm: 1.9.3
gemfile: money-head.gemfile
- rvm: jruby-19mode
gemfile: money-head.gemfile
- rvm: rbx
gemfile: money-head.gemfile
- rvm: ruby-head
bundler_args: --without local_development
script:
- mkdir tmp
- bundle exec rake
15 changes: 15 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
appraise "money-6.0" do
gem "money", "~> 6.0.0"
end

appraise "money-6.1" do
gem "money", "~> 6.1.0"
end

appraise "money-6.2" do
gem "money", "~> 6.2.0"
end

appraise "money-head" do
gem "money", github: "RubyMoney/money"
end
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2014-11-17 - Alexander Simonov
* Version 2.1
* Code refactoring
* Add support for load rates from cache
* Remove support for Money 5.x
2014-03-28 - Matias Korhonen
* Version 2.0.2
* Fixes the Nordea data URL
Expand Down
20 changes: 18 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
source "http://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in nordea.gemspec
gemspec

group :test do
gem 'simplecov', '>= 0.9.0', require: false
gem 'coveralls', require: false
end

group :local_development do
gem 'appraisal'
gem 'terminal-notifier-guard', require: false if RUBY_PLATFORM.downcase.include?('darwin')
gem 'guard', '>= 2.0.0'
gem 'guard-rspec', '>= 4.3.1', require: false
gem 'guard-bundler', require: false
gem 'guard-preek', require: false
gem 'guard-rubocop', require: false
gem 'guard-reek', github: 'pericles/guard-reek', require: false
gem 'pry'
end
19 changes: 19 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
guard 'rspec', cmd: 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end

guard 'bundler' do
watch('Gemfile')
watch('nordea.gemspec')
end

guard :rubocop do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

guard :preek, run_all_dir: 'lib' do
watch(/^lib\/(.*).rb/)
end
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ The Money gem integration works in a similar way to the [eu\_central\_bank](http
nordea_bank = Nordea::Bank.new
Money.default_bank = nordea_bank

# Load rates
nordea_bank.update_rates

# Exchange 100 EUR to USD
nordea_bank.exchange(100, "EUR", "USD")

Expand All @@ -32,9 +35,16 @@ The Money gem integration works in a similar way to the [eu\_central\_bank](http
# Exchange 100 Canadian dollars to US dollars
nordea_bank.exchange_with(Money.new(100, "CAD"), "USD")

# Update the forex rates
# Update the rates to latest
nordea_bank.update_rates

# Save rates to cache file
cache = '/tmp/nordea_cache.yml'
nordea_bank.save_rates(cache)

# Load rates from cache file
nordea_bank.update_rates(cache)

### Without the Money gem

exchange_rates = Nordea::ExchangeRates.new
Expand All @@ -51,12 +61,6 @@ The Money gem integration works in a similar way to the [eu\_central\_bank](http
For more information, read the [documentation](http://rubydoc.info/gems/nordea).


Ruby compatibility
------------------

The gem should work with Ruby 1.9.3, Ruby 2.0.0, jRuby, and Rubinius (only Ruby 1.9 is actively targetted).


About the data and data source
------------------------------

Expand Down
12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# encoding: UTF-8
require "bundler/gem_tasks"
require 'bundler/gem_tasks'

require "rake"
require "rake/task"
require 'rake'
require 'rake/task'

require "rspec/core"
require "rspec/core/rake_task"
require 'rspec/core'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
11 changes: 11 additions & 0 deletions defaults.reek
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
NestedIterators:
max_allowed_nesting: 2
UtilityFunction:
enabled: false
IrresponsibleModule:
enabled: false
DuplicateMethodCall:
max_calls: 5
FeatureEnvy:
enabled: false
24 changes: 24 additions & 0 deletions gemfiles/money_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "money", "~> 6.1.0"

group :test do
gem "simplecov", ">= 0.9.0", :require => false
gem "coveralls", :require => false
end

group :local_development do
gem "appraisal"
gem "terminal-notifier-guard", :require => false
gem "guard", ">= 2.0.0"
gem "guard-rspec", ">= 4.3.1", :require => false
gem "guard-bundler", :require => false
gem "guard-preek", :require => false
gem "guard-rubocop", :require => false
gem "guard-reek", :github => "pericles/guard-reek", :require => false
gem "pry"
end

gemspec :path => "../"
24 changes: 24 additions & 0 deletions gemfiles/money_6.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "money", "~> 6.2.0"

group :test do
gem "simplecov", ">= 0.9.0", :require => false
gem "coveralls", :require => false
end

group :local_development do
gem "appraisal"
gem "terminal-notifier-guard", :require => false
gem "guard", ">= 2.0.0"
gem "guard-rspec", ">= 4.3.1", :require => false
gem "guard-bundler", :require => false
gem "guard-preek", :require => false
gem "guard-rubocop", :require => false
gem "guard-reek", :github => "pericles/guard-reek", :require => false
gem "pry"
end

gemspec :path => "../"
24 changes: 24 additions & 0 deletions gemfiles/money_head.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "money", :github => "RubyMoney/money"

group :test do
gem "simplecov", ">= 0.9.0", :require => false
gem "coveralls", :require => false
end

group :local_development do
gem "appraisal"
gem "terminal-notifier-guard", :require => false
gem "guard", ">= 2.0.0"
gem "guard-rspec", ">= 4.3.1", :require => false
gem "guard-bundler", :require => false
gem "guard-preek", :require => false
gem "guard-rubocop", :require => false
gem "guard-reek", :github => "pericles/guard-reek", :require => false
gem "pry"
end

gemspec :path => "../"
65 changes: 34 additions & 31 deletions lib/nordea.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
require "nordea/bank"
require "nordea/exchange_rates"
require "nordea/version"
require "tzinfo"
require 'nordea/bank'
require 'nordea/exchange_rates'
require 'nordea/version'
require 'tzinfo'

# Ruby interface to the Nordea Bank exchange rate data.
module Nordea
# The default timezone, Europe/Helsinki
TZ = TZInfo::Timezone.get("Europe/Helsinki")
TZ = ::TZInfo::Timezone.get('Europe/Helsinki')
extend self

# Parses the datetime format used in the Nordea data.
#
# @example
# Nordea.parse_time("20150101120056") #=> 2015-01-01 10:00:05 UTC
#
# @param [String] the datetime string (YYYYMMDDHHmmSS)
# @return [Time] the string converted into a Time object
def self.parse_time(datetime)
time = Time.utc( datetime[0..3].to_i,
datetime[4..5].to_i,
datetime[6..7].to_i,
datetime[8..9].to_i,
datetime[10..11].to_i,
datetime[11..12].to_i )
class << self
# Parses the datetime format used in the Nordea data.
#
# @example
# Nordea.parse_time("20150101120056") #=> 2015-01-01 10:00:05 UTC
#
# @param [String] the datetime string (YYYYMMDDHHmmSS)
# @return [Time] the string converted into a Time object
def parse_time(datetime)
time = Time.utc(datetime[0..3].to_i,
datetime[4..5].to_i,
datetime[6..7].to_i,
datetime[8..9].to_i,
datetime[10..11].to_i,
datetime[11..12].to_i)

# Convert the local time to UTC time.
TZ.local_to_utc(time)
# Convert the local time to UTC time.
TZ.local_to_utc(time)
rescue
nil
end
end

# Parses the date format used in the Nordea data.
#
# @param [String] the date string (YYYYMMDD)
# @return [Date] the string converted into a Date object
def self.parse_date(date)
Date.new(date[0..3].to_i,
date[4..5].to_i,
date[6..7].to_i)
# Parses the date format used in the Nordea data.
#
# @param [String] the date string (YYYYMMDD)
# @return [Date] the string converted into a Date object
def parse_date(date)
::Date.new(date[0..3].to_i,
date[4..5].to_i,
date[6..7].to_i)
rescue
nil
end
end
end
end
Loading