Class: Iev::Iso639Code
- Inherits:
-
Object
- Object
- Iev::Iso639Code
- Defined in:
- lib/iev/iso_639_code.rb
Overview
TODO:
This needs to be rewritten.
Constant Summary collapse
- COUNTRY_CODES =
YAML.load(IO.read(File.join(__dir__, "iso_639_2.yaml")))
- THREE_CHAR_MEMO =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #find(code_type) ⇒ Object
-
#initialize(two_char_code) ⇒ Iso639Code
constructor
A new instance of Iso639Code.
Constructor Details
#initialize(two_char_code) ⇒ Iso639Code
Returns a new instance of Iso639Code.
12 13 14 15 16 17 18 19 20 |
# File 'lib/iev/iso_639_code.rb', line 12 def initialize(two_char_code) @code = case two_char_code.length when 2 two_char_code else # This is to handle code "nl BE" in the Iev sheet two_char_code.split(" ").first end end |
Class Method Details
.three_char_code(two_char_code, code_type = "terminology") ⇒ Object
32 33 34 35 |
# File 'lib/iev/iso_639_code.rb', line 32 def self.three_char_code(two_char_code, code_type = "terminology") memo_index = [two_char_code, code_type] THREE_CHAR_MEMO[memo_index] ||= new(two_char_code).find(code_type) end |
Instance Method Details
#find(code_type) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/iev/iso_639_code.rb', line 22 def find(code_type) code = country_codes.detect do |key, value| key if value["iso_639_1"] == @code.to_s && value[code_type] end raise StandardError, "Iso639Code not found for '#{@code}'!" if code.nil? code end |