Skip to content

Commit

Permalink
Add glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyhre committed May 15, 2017
1 parent 903fe98 commit 4cc6cd3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,33 @@ def rates
format.csv { send_data csv }
end
end

def glossary
countries = Price.pluck(:country).uniq.sort
currencies = ExchangeRate.pluck(:from).uniq.sort

csv = CSV.generate(headers: true) do |rows|
rows << ['Countries']
rows << ['Country code', 'Country name', 'Currency code', 'Currency name']

countries.each do |code|
country = ISO3166::Country[code]
rows << [code, country.name, country.currency.iso_code, country.currency.name]
end

rows << []

rows << ['Currencies']
rows << ['Currency code', 'Currency name']
currencies.each do |code|
currency = ISO3166::Country.find_country_by_currency(code).currency
rows << [code, currency.name]
end

end

respond_to do |format|
format.csv { send_data csv }
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

get :prices, to: 'application#prices'
get :rates, to: 'application#rates'
get :glossary, to: 'application#glossary'
end

0 comments on commit 4cc6cd3

Please sign in to comment.