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
43 changes: 2 additions & 41 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/money/bank/variable_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def exchange_with(from, to_currency, &)
if from.currency == to_currency
from
else
if rate = get_rate(from.currency, to_currency)
if (rate = get_rate(from.currency, to_currency))
fractional = calculate_fractional(from, to_currency)
from.dup_with(
fractional: exchange(fractional, rate, &),
Expand Down Expand Up @@ -175,7 +175,7 @@ def add_rate(from, to, rate)
# bank = Money::Bank::VariableExchange.new
# bank.set_rate("USD", "CAD", 1.24515)
# bank.set_rate("CAD", "USD", 0.803115)
def set_rate(from, to, rate, opts = {})
def set_rate(from, to, rate, _opts = {})
store.add_rate(Currency.wrap(from).iso_code, Currency.wrap(to).iso_code, rate)
end

Expand All @@ -196,7 +196,7 @@ def set_rate(from, to, rate, opts = {})
#
# bank.get_rate("USD", "CAD") #=> 1.24515
# bank.get_rate("CAD", "USD") #=> 0.803115
def get_rate(from, to, opts = {})
def get_rate(from, to, _opts = {})
store.get_rate(Currency.wrap(from).iso_code, Currency.wrap(to).iso_code)
end

Expand All @@ -219,7 +219,7 @@ def get_rate(from, to, opts = {})
#
# s = bank.export_rates(:json)
# s #=> "{\"USD_TO_CAD\":1.24515,\"CAD_TO_USD\":0.803115}"
def export_rates(format, file = nil, opts = {})
def export_rates(format, file = nil, _opts = {})
raise Money::Bank::UnknownRateFormat unless RATE_FORMATS.include?(format)

store.transaction do
Expand Down Expand Up @@ -259,7 +259,7 @@ def rates
#
# bank.get_rate("USD", "CAD") #=> 1.24515
# bank.get_rate("CAD", "USD") #=> 0.803115
def import_rates(format, string, opts = {})
def import_rates(format, string, _opts = {})
raise Money::Bank::UnknownRateFormat unless RATE_FORMATS.include?(format)

if format == :ruby
Expand Down
2 changes: 1 addition & 1 deletion lib/money/currency/heuristics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Money
class Currency
module Heuristics
def analyze(str)
def analyze(_str)
raise StandardError, 'Heuristics deprecated, add `gem "money-heuristics"` to Gemfile'
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/money/locale_backend/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class I18n < Base

def initialize
raise NotSupported, 'I18n not found' unless defined?(::I18n)

super
end

def lookup(key, _)
Expand Down
2 changes: 2 additions & 0 deletions lib/money/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ def self.setup_defaults

def self.inherited(base)
base.setup_defaults

super
end

setup_defaults
Expand Down
1 change: 1 addition & 0 deletions lib/money/money/arithmetic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def <=>(other)
other = other.exchange_to(currency)
fractional <=> other.fractional
rescue Money::Bank::UnknownRate
nil
end

# Uses Comparable's implementation but raises ArgumentError if non-zero
Expand Down
2 changes: 1 addition & 1 deletion lib/money/money/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def append_sign(formatted_number)
.gsub('%u', [sign_before, symbol_value].join)
.gsub('%n', [sign, formatted_number].join)
else
formatted_number = "#{sign_before}#{sign}#{formatted_number}"
"#{sign_before}#{sign}#{formatted_number}"
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/money/arithmetic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@
expect(Money.new(1, "USD")).not_to eq 0
end

# rubocop:disable Lint/FloatComparison
it 'raises error for non-zero numerics' do
expect { Money.new(1_00, "USD") == 1 }.to raise_error ArgumentError
expect { Money.new(1_00, "USD") == -2.0 }.to raise_error ArgumentError
expect { Money.new(1_00, "USD") == Float::INFINITY }.to raise_error ArgumentError
end
# rubocop:enable Lint/FloatComparison
end

describe "#eql?" do
Expand Down Expand Up @@ -110,6 +112,7 @@
end
end

# rubocop:disable Lint/FloatComparison
it "returns false if used to compare with an object that doesn't inherit from Money" do
expect(Money.new(1_00, "USD").eql?(Object.new)).to be false
expect(Money.new(1_00, "USD").eql?(Class)).to be false
Expand All @@ -120,6 +123,7 @@
expect(Money.new(1_00, "USD").eql?(1)).to be false
expect(Money.new(1_00, "USD").eql?(1_00)).to be false
end
# rubocop:enable Lint/FloatComparison

it "can be used to compare with an object that inherits from Money" do
klass = Class.new(Money)
Expand Down
2 changes: 1 addition & 1 deletion spec/money/formatting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
expect(Money.new(100, "SEK").format(symbol: true)).to eq "1,00 kr"
end

specify "(symbol: "", nil or false) returns the amount without a symbol" do
specify "(symbol: \"\", nil or false) returns the amount without a symbol" do
money = Money.new(100, "GBP")
expect(money.format(symbol: "")).to eq "1.00"
expect(money.format(symbol: nil)).to eq "1.00"
Expand Down