Skip to content

Instantly share code, notes, and snippets.

@ilake
Last active December 25, 2015 08:19
Show Gist options
  • Save ilake/6945171 to your computer and use it in GitHub Desktop.
Save ilake/6945171 to your computer and use it in GitHub Desktop.
require "i18n" rescue LoadError
module Money::Currency::Loader
  extend self

  DATA_PATH = File.expand_path("../../../../config", __FILE__)

  # Loads and returns the currencies stored in JSON files in the config directory.
  #
  # @return [Hash]
  def load_currencies
    currencies = parse_currency_file("currency.json")
    currencies.merge! parse_currency_file("currency_bc.json")
  end

  private

  def parse_currency_file(filename)
    json = File.read("#{DATA_PATH}/#{filename}")
    json.force_encoding(::Encoding::UTF_8) if defined?(::Encoding)
    JSON.parse(json, :symbolize_names => true)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment