Sha256: 911e503ad9c94b6c476efa171abf3aedb614cc71313675addf8eb2144d1025f3

Contents?: true

Size: 1.06 KB

Versions: 21

Compression:

Stored size: 1.06 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'nokogiri'
require 'open-uri'

module TwitterCldr
  module Resources

    class CurrencySymbolsImporter < Importer

      URL = 'https://www.xe.com/symbols.php'.freeze

      output_path 'shared'
      ruby_engine :mri

      private

      def execute
        path = File.join(params[:output_path], 'iso_currency_symbols.yml')

        File.open(path, 'w:utf-8') do |output|
          output.write(
            TwitterCldr::Utils::YAML.dump(
              TwitterCldr::Utils.deep_symbolize_keys(symbol_data),
              use_natural_symbols: true
            )
          )
        end
      end

      def symbol_data
        doc = Nokogiri::HTML(URI.open(URL).read)
        rows = doc.css('.currencySymblTable tr')

        rows[1..-1].each_with_object({}) do |row, ret|
          code = row.css('td')[1].text
          symbol = row.css('td.cSmbl_Fnt_C2000').text
          ret[code] = { code_points: symbol.codepoints, symbol: symbol }
        end
      end

    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
twitter_cldr-6.11.5 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.11.4 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.11.3 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.11.2 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.11.1 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.11.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.10.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.9.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.8.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.7.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.6.2 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.6.1 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.6.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.5.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.4.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.3.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.2.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.1.0 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.0.2 lib/twitter_cldr/resources/currency_symbols_importer.rb
twitter_cldr-6.0.1 lib/twitter_cldr/resources/currency_symbols_importer.rb