DEV Community

Kentaro Kuribayashi
Kentaro Kuribayashi

Posted on

Generating Currency-code-like Name in Ruby

Various currencies around. Moreover, rising of crypto currencies increases the number of currency-like stores of value. We will dare to add some into it. At the time, naming currency is a problem.

What's the Currency Codes?

ISO 4217 delineates how to shorten currency name; currency codes.

The first two letters of the code are the two letters of the ISO 3166-1 alpha-2 country codes (an omission) and the third is usually the initial of the currency itself. So Japan's currency code is JPY—JP for Japan and Y for yen.

ISO 4217 - Wikipedia

Currency Codes for Smart Tokens

Since I had wanted similar one for original currencies backed by smart tokens, I hacked up a tiny library for Ruby named currency_coder.

currency_coder gem

This library converts arbitrary strings (e.g. your name) to currency-code-like short name as below:

cc = CurrencyCoder.new

currency_map = {
  "osamu"    => "OSM",
  "mayoto"   => "MYT",
  "kurotaki" => "KRT",
  "putchom"  => "PTM",
  "antipop"  => "ATP",
  "jitsuzon" => "JZN"
}

currency_map.each do |name, code|
  assert_equal code, cc.as_currency_code(name)
end
Enter fullscreen mode Exit fullscreen mode

Let's create your own currency using this library!

Top comments (0)