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 =
rubocop:disable Style/MutableConstant
{}
Class Method Summary collapse
Instance Method Summary collapse
- #find(code_type) ⇒ Object
-
#initialize(two_char_code) ⇒ Iso639Code
constructor
rubocop:enable Style/MutableConstant.
Constructor Details
#initialize(two_char_code) ⇒ Iso639Code
rubocop:enable Style/MutableConstant
14 15 16 17 18 19 20 21 22 |
# File 'lib/iev/iso_639_code.rb', line 14 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
34 35 36 37 |
# File 'lib/iev/iso_639_code.rb', line 34 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
24 25 26 27 28 29 30 31 32 |
# File 'lib/iev/iso_639_code.rb', line 24 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 |