Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Refactor currency converter #1

Merged
merged 4 commits into from

2 participants

@gitlaura
Owner
  • Cleaned calculator
  • Refactored unneccesary dependency injection in currency_converter
@gitlaura
Owner
  • added OpenStructs
  • deleted unneccessary code and tests
lib/transaction_parser.rb
((7 lines not shown))
- file = File.open(csv_file).read
- file.each_line do |line|
- all_transactions << create_transaction(line)
+ class << self
+
+ def parse(csv_file)
+ all_transactions = []
+ file = File.open(csv_file).read
+ file.each_line do |line|
+ all_transactions << create_transaction(line)
+ end
+ all_transactions
+ end
+
+ def create_transaction(line)
+ @store, @sku, @amount = line.chomp.split(",")
@ryanzverner Collaborator

Do these need to be instance variables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
spec/calculator_spec.rb
((5 lines not shown))
describe "Calculator interface" do
before(:each) do
- @calculator = Calculator.new
+ @rates_file = "SAMPLE_RATES.xml"
@ryanzverner Collaborator

Read this and this and this about using let instead of instance variables in specs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gitlaura
Owner
  • Refactored spec files to include let instead of instance variables
  • Removed instance varables from transaction parser
@ryanzverner ryanzverner merged commit badb505 into master
@ryanzverner ryanzverner deleted the refactor_currency_converter branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 11, 2014
  1. update currency_converter

    authored
  2. refactor and add OpenStructs

    authored
Commits on Jul 15, 2014
This page is out of date. Refresh to see the latest.
View
5 lib/add_amounts.rb
@@ -1,5 +0,0 @@
-class AddAmounts
- def add(amounts)
- amounts.reduce(:+)
- end
-end
View
36 lib/calculator.rb
@@ -2,31 +2,27 @@
require_relative 'transaction_parser.rb'
require_relative 'sort_by_sku.rb'
require_relative 'currency_converter.rb'
-require_relative 'add_amounts.rb'
class Calculator
- attr_reader :rates, :transactions, :sorted_transactions, :converted_amounts
+ class << self
+ def get_conversion_rates(rate_file)
+ RatesParser.parse(rate_file)
+ end
- def get_conversion_rates(rate_file)
- rates_parser = RatesParser.new
- @rates = rates_parser.parse(rate_file)
- end
+ def get_transactions(trans_file)
+ TransactionParser.parse(trans_file)
+ end
- def get_transactions(trans_file)
- transaction_parser = TransactionParser.new
- @transactions = transaction_parser.parse(trans_file)
- end
+ def sort_transactions(sku, transactions)
+ SortBySku.sort(sku, transactions)
+ end
- def sort_transactions(sku, transactions = @transactions)
- sort_by_sku = SortBySku.new
- @sorted_transactions = sort_by_sku.sort(sku, transactions)
- end
-
- def convert_transactions(to_currency, rates = @rates, sorted_transactions = @sorted_transactions)
- @converted_amounts = CurrencyConverter.new.convert(to_currency, rates, sorted_transactions)
- end
+ def convert_transactions(to_currency, rates, sorted_transactions)
+ CurrencyConverter.new(to_currency, rates).convert(sorted_transactions)
+ end
- def add_sorted_transactions(amounts = @converted_amounts)
- AddAmounts.new.add(amounts)
+ def add_sorted_transactions(amounts)
+ amounts.reduce(:+).round(2)
+ end
end
end
View
52 lib/currency_converter.rb
@@ -1,12 +1,14 @@
class CurrencyConverter
- def convert(to_currency, rates, transactions)
+ attr_reader :to_currency, :rates, :transactions, :amounts
+
+ def initialize(to_currency, rates)
@to_currency = to_currency
@rates = rates
- @transactions = transactions
@amounts = []
- @final_conversion_rate = 1.0
+ end
- @transactions.each do |trans|
+ def convert(transactions)
+ transactions.each do |trans|
if conversion_unnecessary?(trans)
@amounts << trans.original_amount.to_f
else
@@ -16,47 +18,41 @@ def convert(to_currency, rates, transactions)
@amounts
end
- def conversion_unnecessary?(trans, to_currency = @to_currency)
- return true if trans.original_currency == to_currency
+ def conversion_unnecessary?(trans)
+ return true if trans.original_currency == @to_currency
return false
end
- def convert_amount(original_currency, original_amount, to_currency = @to_currency, rates = @rates)
+ def convert_amount(original_currency, original_amount)
rate = get_conversion_rate(original_currency)
(rate * original_amount.to_f).round(2)
end
- def get_conversion_rate(original_currency, final_conversion_rate = @final_conversion_rate, to_currency = @to_currency, rates = @rates)
+ def get_conversion_rate(original_currency, final_conversion_rate = 1.00)
if exact_match?(original_currency)
- new_rate = calculate_final_rate(original_currency)
- return final_conversion_rate *= new_rate
- elsif from_currency_matches?(original_currency)
- final_conversion_rate *= calculate_rate(original_currency)
- new_original_currency = update_original_currency(original_currency)
+ new_rate = get_exact_matching_rate(original_currency)
+ return final_conversion_rate * new_rate.rate
+ else
+ current_rate = rate_with_same_from_currency(original_currency)
+ final_conversion_rate *= current_rate.rate
+ new_original_currency = current_rate.to_currency
get_conversion_rate(new_original_currency, final_conversion_rate)
end
end
- def exact_match?(original_currency, to_currency = @to_currency, rates = @rates)
- !(rates.select {|rate| rate.from_currency == original_currency && rate.to_currency == to_currency}).empty?
- end
-
- def calculate_final_rate(original_currency, to_currency = @to_currency, rates = @rates)
- matching_rates = rates.select {|rate| rate.from_currency == original_currency && rate.to_currency == to_currency}
- matching_rates[0].rate
+ def exact_match?(original_currency)
+ rates_with_exact_matches(original_currency).size > 0
end
- def from_currency_matches?(original_currency, to_currency = @to_currency, rates = @rates)
- !(rates.select {|rate| rate.from_currency == original_currency}).empty?
+ def get_exact_matching_rate(original_currency)
+ rates_with_exact_matches(original_currency)[0]
end
- def calculate_rate(original_currency, rates = @rates)
- matching_rates = rates.select {|rate| rate.from_currency == original_currency}
- matching_rates[0].rate
+ def rates_with_exact_matches(original_currency)
+ @rates.select {|rate| rate.from_currency == original_currency && rate.to_currency == @to_currency}
end
- def update_original_currency(original_currency, rates = @rates)
- matching_rates = rates.select {|rate| rate.from_currency == original_currency}
- matching_rates[0].to_currency
+ def rate_with_same_from_currency(original_currency)
+ (@rates.select {|rate| rate.from_currency == original_currency})[0]
end
end
View
9 lib/rate.rb
@@ -1,9 +0,0 @@
-class Rate
- attr_accessor :from_currency, :to_currency, :rate
-
- def initialize(from_currency = nil, to_currency = nil, rate = nil)
- @from_currency = from_currency
- @to_currency = to_currency
- @rate = rate
- end
-end
View
87 lib/rates_parser.rb
@@ -1,62 +1,55 @@
-require_relative 'rate.rb'
+require 'ostruct'
class RatesParser
attr_reader :all_rates
- def initialize
- @all_rates = []
- end
-
- def parse(xml_file)
- file = File.open(xml_file).read
-
- file.each_line do |line|
- line.strip!
- create_new_rate if is_rate?(line)
- set_from_currency(line) if is_from_currency?(line)
- set_to_currency(line) if is_to_currency?(line)
- set_rate(line) if is_conversion?(line)
- @all_rates << @new_rate if is_end_rate?(line)
+ class << self
+
+ def parse(xml_file)
+ file = File.open(xml_file)
+ all_rates = []
+
+ file.each_line do |line|
+ line.strip!
+ @from_currency = get_from_currency(line) if is_from_currency?(line)
+ @to_currency = get_to_currency(line) if is_to_currency?(line)
+ @rate = get_rate(line) if is_conversion?(line)
+ if is_end_rate?(line)
+ new_rate = OpenStruct.new(:from_currency => @from_currency, :to_currency => @to_currency, :rate => @rate)
+ all_rates << new_rate
+ end
+ end
+ all_rates
end
-
- @all_rates
- end
-
- private
- def is_rate?(line)
- line[1..5] == "rate>"
- end
+ private
- def is_from_currency?(line)
- line[1..4] == "from"
- end
-
- def is_to_currency?(line)
- line[1..2] == "to"
- end
+ def is_from_currency?(line)
+ line[1..4] == "from"
+ end
- def is_conversion?(line)
- line[1..3] == "con"
- end
+ def is_to_currency?(line)
+ line[1..2] == "to"
+ end
- def is_end_rate?(line)
- line[1..6] == "/rate>"
- end
+ def is_conversion?(line)
+ line[1..3] == "con"
+ end
- def create_new_rate
- @new_rate = Rate.new
- end
+ def is_end_rate?(line)
+ line[1..6] == "/rate>"
+ end
- def set_from_currency(line)
- @new_rate.from_currency = line[6..8]
- end
+ def get_from_currency(line)
+ line[6..8]
+ end
- def set_to_currency(line)
- @new_rate.to_currency = line[4..6]
- end
+ def get_to_currency(line)
+ line[4..6]
+ end
- def set_rate(line)
- @new_rate.rate = line[12..17].to_f
+ def get_rate(line)
+ line[12..17].to_f
+ end
end
end
View
18 lib/runner.rb
@@ -1,17 +1,11 @@
require_relative 'calculator.rb'
class Runner
- attr_reader :calculator
-
- def initialize
- @calculator = Calculator.new
- end
-
- def run_international_calculator(sku = "DM1210", transactions_file = "SAMPLE_TRANS.csv", rates_file = "SAMPLE_RATES.xml", final_currency = "USD")
- @calculator.get_conversion_rates(rates_file)
- @calculator.get_transactions(transactions_file)
- @calculator.sort_transactions(sku)
- @calculator.convert_transactions(final_currency)
- @calculator.add_sorted_transactions
+ def run_international_calculator(sku, transactions_file, rates_file, final_currency)
+ rates = Calculator.get_conversion_rates(rates_file)
+ transactions = Calculator.get_transactions(transactions_file)
+ sorted_transactions = Calculator.sort_transactions(sku, transactions)
+ converted_totals = Calculator.convert_transactions(final_currency,rates,sorted_transactions)
+ Calculator.add_sorted_transactions(converted_totals)
end
end
View
2  lib/sort_by_sku.rb
@@ -1,5 +1,5 @@
class SortBySku
- def sort(sku, transactions)
+ def self.sort(sku, transactions)
output = []
transactions.each do |trans|
if trans.sku == sku
View
9 lib/transaction.rb
@@ -1,9 +0,0 @@
-class Transaction
- attr_reader :store, :sku, :original_currency, :original_amount
-
- def initialize(store, sku, amount)
- @store = store
- @sku = sku
- @original_amount, @original_currency = amount.split(" ")
- end
-end
View
27 lib/transaction_parser.rb
@@ -1,17 +1,22 @@
-require_relative 'transaction.rb'
+require 'ostruct'
class TransactionParser
- def parse(csv_file)
- all_transactions = []
- file = File.open(csv_file).read
- file.each_line do |line|
- all_transactions << create_transaction(line)
+ class << self
+
+ def parse(csv_file)
+ all_transactions = []
+ file = File.open(csv_file).read
+ file.each_line do |line|
+ all_transactions << create_transaction(line)
+ end
+ all_transactions
+ end
+
+ def create_transaction(line)
+ store, sku, amount = line.chomp.split(",")
+ original_amount, original_currency = amount.split(" ")
+ OpenStruct.new(:store => store, :sku => sku, :original_amount => original_amount, :original_currency => original_currency)
end
- all_transactions
- end
- def create_transaction(line)
- store, sku, amount = line.chomp.split(",")
- Transaction.new(store, sku, amount)
end
end
View
12 spec/add_amounts_spec.rb
@@ -1,12 +0,0 @@
-require 'add_amounts'
-
-describe "Add Amounts" do
- before(:each) do
- @add_amounts = AddAmounts.new
- end
-
- it "adds together numbers in an array" do
- expect(@add_amounts.add([5.00,6.00])).to eq(11.00)
- expect(@add_amounts.add([5.50,6.25,3.32])).to eq(15.07)
- end
-end
View
51 spec/calculator_spec.rb
@@ -1,49 +1,42 @@
require 'calculator'
-require 'transaction'
-require 'rate'
+require 'ostruct'
describe "Calculator interface" do
- before(:each) do
- @calculator = Calculator.new
- end
+ let(:rates_file) {"SAMPLE_RATES.xml"}
+ let(:trans_file) {"SAMPLE_TRANS.csv"}
+ let(:trans_001) {OpenStruct.new(:store => "Yonkers", :sku => "DM1182", :original_amount => "19.68", :original_currency => "AUD")}
+ let(:trans_002) {OpenStruct.new(:store => "Nashua", :sku => "DM1182", :original_amount => "58.58", :original_currency => "AUD")}
+ let(:trans_003) {OpenStruct.new(:store => "Camden", :sku => "DM1182", :original_amount => "54.64", :original_currency => "USD")}
+ let(:rate_one) {OpenStruct.new(:from_currency => "AUD", :to_currency => "CAD", :rate => 1.0079)}
+ let(:rate_two) {OpenStruct.new(:from_currency => "CAD", :to_currency => "USD", :rate => 1.0090)}
+ let(:rate_three) {OpenStruct.new(:from_currency => "USD", :to_currency => "CAD", :rate => 0.9911)}
+ let(:sku) {"DM1182"}
+ let(:to_currency) {"USD"}
+ let(:transactions) {[trans_001, trans_002, trans_003]}
+ let(:rates) {[rate_one, rate_two, rate_three]}
it "gets a list of rates" do
- file = "SAMPLE_RATES.xml"
- @calculator.get_conversion_rates(file)
- expect(@calculator.rates.size).to eq(3)
+ rates = Calculator.get_conversion_rates(rates_file)
+ expect(rates.size).to eq(3)
end
it "gets a list of transactions" do
- file = "SAMPLE_TRANS.csv"
- @calculator.get_transactions(file)
- expect(@calculator.transactions.size).to eq(6)
+ transactions = Calculator.get_transactions(trans_file)
+ expect(transactions.size).to eq(6)
end
it "sorts transactions by SKU" do
- trans_001 = Transaction.new("Yonkers","DM1210","70.00 USD")
- trans_002 = Transaction.new("Nashua","DM1182","58.58 AUD")
- trans_003 = Transaction.new("Camden","DM1182","54.64 USD")
- transactions = [trans_001, trans_002, trans_003]
- sku = "DM1182"
- @calculator.sort_transactions(sku, transactions)
- expect(@calculator.sorted_transactions.size).to eq(2)
+ sorted_transactions = Calculator.sort_transactions(sku, transactions)
+ expect(sorted_transactions.size).to eq(3)
end
it "converts sorted transactions" do
- to_currency = "USD"
- trans_002 = Transaction.new("Nashua","DM1182","58.58 AUD")
- trans_003 = Transaction.new("Camden","DM1182","54.64 USD")
- sorted_transactions = [trans_002, trans_003]
- rate_one = Rate.new("AUD","CAD",1.0079)
- rate_two = Rate.new("CAD","USD",1.0090)
- rate_three = Rate.new("USD","CAD",0.9911)
- rates = [rate_one, rate_two, rate_three]
- @calculator.convert_transactions(to_currency,rates,sorted_transactions)
- expect(@calculator.converted_amounts).to eq([59.57,54.64])
+ converted_amounts = Calculator.convert_transactions(to_currency, rates, transactions)
+ expect(converted_amounts).to eq([20.01,59.57,54.64])
end
it "adds transactions in USD" do
amounts = [15.00, 15.45, 19.20]
- expect(@calculator.add_sorted_transactions(amounts)).to eq(49.65)
+ expect(Calculator.add_sorted_transactions(amounts)).to eq(49.65)
end
end
View
66 spec/currency_converter_spec.rb
@@ -1,64 +1,50 @@
require 'currency_converter'
-require 'rate'
-require 'transaction'
+require 'ostruct'
describe "Currency Converter" do
- before(:each) do
- @currency_converter = CurrencyConverter.new
- @to_currency = "USD"
- @trans_two = Transaction.new("Nashua","DM1182","58.58 AUD")
- @trans_three = Transaction.new("Camden","DM1182","54.64 USD")
- @sorted_transactions = [@trans_two, @trans_three]
- rate_one = Rate.new("AUD","CAD",1.0079)
- rate_two = Rate.new("CAD","USD",1.0090)
- rate_three = Rate.new("USD","CAD",0.9911)
- @rates = [rate_one, rate_two, rate_three]
- end
+ let(:to_currency) {"USD"}
+ let(:rate_one) {OpenStruct.new(:from_currency => "AUD", :to_currency => "CAD", :rate => 1.0079)}
+ let(:rate_two) {OpenStruct.new(:from_currency => "CAD", :to_currency => "USD", :rate => 1.0090)}
+ let(:rate_three) {OpenStruct.new(:from_currency => "USD", :to_currency => "CAD", :rate => 0.9911)}
+ let(:rates) {[rate_one, rate_two, rate_three]}
+ let(:trans_one) {OpenStruct.new(:store => "Nashua", :sku => "DM1182", :original_amount => "58.58", :original_currency => "AUD")}
+ let(:trans_two) {OpenStruct.new(:store => "Camden", :sku => "DM1182", :original_amount => "54.64", :original_currency => "USD")}
+ let(:sorted_transactions) {[trans_one, trans_two]}
+ let(:currency_converter) {CurrencyConverter.new(to_currency, rates)}
it "converts transactions into converted amounts" do
- amounts = @currency_converter.convert(@to_currency, @rates, @sorted_transactions)
+ amounts = currency_converter.convert(sorted_transactions)
expect(amounts).to eq([59.57,54.64])
end
it "determines if a conversion is not needed" do
- expect(@currency_converter.conversion_unnecessary?(@trans_two, "USD")).to eq(false)
- expect(@currency_converter.conversion_unnecessary?(@trans_three, "USD")).to eq(true)
+ expect(currency_converter.conversion_unnecessary?(trans_one)).to eq(false)
+ expect(currency_converter.conversion_unnecessary?(trans_two)).to eq(true)
end
it "converts amounts" do
- expect(@currency_converter).to receive(:get_conversion_rate) {1.0090}
- amount = @currency_converter.convert_amount("AUD", 50.00)
+ expect(currency_converter).to receive(:get_conversion_rate) {1.0090}
+ amount = currency_converter.convert_amount("AUD", 50.00)
expect(amount).to eq(50.45)
end
- it "gets conversion rate for any currency to final currency" do
- expect(@currency_converter).to receive(:exact_match?) {true}
- expect(@currency_converter).to receive(:calculate_final_rate) {1.0090}
- final_rate = @currency_converter.get_conversion_rate("AUD", 1.00, @to_currency, @rates)
- expect(final_rate).to eq(1.0090)
- end
-
it "checks for an exact match of currencies" do
- expect(@currency_converter.exact_match?("CAD", @to_currency, @rates)).to eq(true)
- expect(@currency_converter.exact_match?("AUD", @to_currency, @rates)).to eq(false)
- end
-
- it "calculates final rate" do
- rate = @currency_converter.calculate_final_rate("CAD", @to_currency, @rates)
- expect(rate).to eq(1.0090)
+ expect(currency_converter.exact_match?("CAD")).to eq(true)
+ expect(currency_converter.exact_match?("AUD")).to eq(false)
end
- it "checks for rates with the same from_currencies" do
- expect(@currency_converter.from_currency_matches?("AUD", @to_currency, @rates)).to eq(true)
+ it "gets exact matching rate object" do
+ rate = currency_converter.get_exact_matching_rate("CAD")
+ expect(rate.rate).to eq(1.0090)
end
- it "calculates rate from the same from_currencies" do
- rate = @currency_converter.calculate_rate("AUD", @rates)
- expect(rate).to eq(1.0079)
+ it "returns rates that match to and from currency" do
+ rates = currency_converter.rates_with_exact_matches("CAD")
+ expect(rates.size).to eq(1)
end
- it "updates from_currency for next conversion" do
- rate = @currency_converter.update_original_currency("AUD", @rates)
- expect(rate).to eq("CAD")
+ it "returns rates that just the from currency" do
+ rates = currency_converter.rate_with_same_from_currency("AUD")
+ expect(rates).to be_a(Object)
end
end
View
16 spec/rate_spec.rb
@@ -1,16 +0,0 @@
-require 'rate'
-
-describe "Rate" do
- before(:each) do
- @rate = Rate.new
- @rate.from_currency = "CAD"
- @rate.to_currency = "USD"
- @rate.rate = "1.0090".to_f
- end
-
- it "captures currencies and rate" do
- expect(@rate.from_currency).to eq("CAD")
- expect(@rate.to_currency).to eq("USD")
- expect(@rate.rate).to eq(1.0090)
- end
-end
View
11 spec/rates_parser_spec.rb
@@ -1,14 +1,11 @@
require 'rates_parser'
describe "Rates parser" do
- before(:each) do
- @rates_parser = RatesParser.new
- end
-
it "parses an xml currency rates file" do
file = "SAMPLE_RATES.xml"
- expect(@rates_parser.parse(file)[0].from_currency).to eq("AUD")
- expect(@rates_parser.parse(file)[1].to_currency).to eq("USD")
- expect(@rates_parser.parse(file)[2].rate).to eq(0.9911)
+ rates = RatesParser.parse(file)
+ expect(rates[0].from_currency).to eq("AUD")
+ expect(rates[1].to_currency).to eq("USD")
+ expect(rates[2].rate).to eq(0.9911)
end
end
View
13 spec/runner_spec.rb
@@ -2,12 +2,11 @@
describe "Runner" do
it "runs international calc" do
- @runner = Runner.new
- expect(@runner.calculator).to receive(:get_conversion_rates)
- expect(@runner.calculator).to receive(:get_transactions)
- expect(@runner.calculator).to receive(:sort_transactions)
- expect(@runner.calculator).to receive(:convert_transactions)
- expect(@runner.calculator).to receive(:add_sorted_transactions)
- @runner.run_international_calculator("DM1210", "SAMPLE_TRANS.csv", "SAMPLE_RATES.xml")
+ expect(Calculator).to receive(:get_conversion_rates)
+ expect(Calculator).to receive(:get_transactions)
+ expect(Calculator).to receive(:sort_transactions)
+ expect(Calculator).to receive(:convert_transactions)
+ expect(Calculator).to receive(:add_sorted_transactions)
+ Runner.new.run_international_calculator("DM1210", "SAMPLE_TRANS.csv", "SAMPLE_RATES.xml", "USD")
end
end
View
12 spec/sort_by_sku_spec.rb
@@ -1,15 +1,13 @@
require 'sort_by_sku'
-require 'transaction'
+require 'ostruct'
describe "Sort by SKU" do
it "returns an array of transactions for chosen sku" do
- trans_001 = Transaction.new("Yonkers","DM1210","70.00 USD")
- trans_002 = Transaction.new("Nashua","DM1182","58.58 AUD")
- trans_003 = Transaction.new("Camden","DM1182","54.64 USD")
+ trans_001 = OpenStruct.new(:store => "Yonkers", :sku => "DM1210", :original_amount => "19.68", :original_currency => "AUD")
+ trans_002 = OpenStruct.new(:store => "Nashua", :sku => "DM1182", :original_amount => "58.58", :original_currency => "AUD")
+ trans_003 = OpenStruct.new(:store => "Camden", :sku => "DM1182", :original_amount => "54.64", :original_currency => "USD")
transactions = [trans_001, trans_002, trans_003]
sku = "DM1182"
-
- sort_by_sku = SortBySku.new
- expect(sort_by_sku.sort(sku, transactions)).to eq([trans_002, trans_003])
+ expect(SortBySku.sort(sku, transactions)).to eq([trans_002, trans_003])
end
end
View
13 spec/transaction_parser_spec.rb
@@ -1,17 +1,14 @@
require 'transaction_parser'
-require 'rate'
describe "Transaction parser" do
+ let(:file) {"SAMPLE_TRANS.csv"}
+
it "parses a csv trans file" do
- file = "SAMPLE_TRANS.csv"
- transaction_parser = TransactionParser.new
- expect(transaction_parser.parse(file).size).to eq(6)
+ expect(TransactionParser.parse(file).size).to eq(6)
end
- it "creates a transaction" do
- file = "SAMPLE_TRANS.csv"
- transaction_parser = TransactionParser.new
- result = transaction_parser.create_transaction("Yonkers,DM1210,70.00 USD")
+ it "creates a transaction" do
+ result = TransactionParser.create_transaction("Yonkers,DM1210,70.00 USD")
expect(result.store).to eq("Yonkers")
expect(result.sku).to eq("DM1210")
expect(result.original_currency).to eq("USD")
View
19 spec/transaction_spec.rb
@@ -1,19 +0,0 @@
-require 'transaction'
-require 'rate'
-
-describe "Transaction" do
-
- it "creates a store, SKU, amount, and currency" do
- @transaction = Transaction.new("Yonkers","DM1210","70.00 USD")
- expect(@transaction.store).to eq("Yonkers")
- expect(@transaction.sku).to eq("DM1210")
- expect(@transaction.original_amount).to eq("70.00")
- expect(@transaction.original_currency).to eq("USD")
- end
-
- it "stores international currency as AUD" do
- @transaction = Transaction.new("Yonkers","DM1210","70.00 AUD")
- expect(@transaction.original_amount).to eq("70.00")
- expect(@transaction.original_currency).to eq("AUD")
- end
-end
View
2  start.rb
@@ -1,4 +1,4 @@
require_relative 'lib/runner.rb'
runner = Runner.new
-puts runner.run_international_calculator("DM1210")
+puts runner.run_international_calculator("DM1182", "SAMPLE_TRANS.csv","SAMPLE_RATES.xml", "USD")
Something went wrong with that request. Please try again.