class ISO_639
Constants
- INVERTED_INDEX
An inverted index generated from the
ISO_639_2
data. Used for searching all words and codes in all fields.- ISO_639_1
The ISO 639-1 dataset as an array of entries. Each entry is an array with the following format:
-
[0]: an ISO 369-2 alpha-3 (bibliographic) code
-
[1]: an ISO 369-2 alpha-3 (terminologic) code (when given)
-
[2]: an ISO 369-1 alpha-2 code (when given)
-
[3]: an English name
-
[4]: a French name
-
- ISO_639_2
Load the ISO 639-2 dataset as an array of entries. Each entry is an array with the following format:
-
[0]: an alpha-3 (bibliographic) code
-
[1]: an alpha-3 (terminologic) code (when given)
-
[2]: an alpha-2 code (when given)
-
[3]: an English name
-
[4]: a French name of a language
Dataset Source: www.loc.gov/standards/iso639-2/ascii_8bits.html www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
-
Public Class Methods
Returns the entry array for an alpha-2 or alpha-3 code
# File lib/iso-639.rb, line 65 def find_by_code(code) return if code.nil? case code.length when 3 ISO_639_2.detect do |entry| entry if [entry.alpha3, entry.alpha3_terminologic].include?(code) end when 2 ISO_639_1.detect do |entry| entry if entry.alpha2 == code end end end
Returns the entry array for a language specified by its English name.
# File lib/iso-639.rb, line 82 def find_by_english_name(name) ISO_639_2.detect do |entry| entry if entry.english_name == name end end
Returns the entry array for a language specified by its French name.
# File lib/iso-639.rb, line 89 def find_by_french_name(name) ISO_639_2.detect do |entry| entry if entry.french_name == name end end
Returns an array of matches for the search term. The term can be a code of any kind, or it can be one of the words contained in the English or French name field.
# File lib/iso-639.rb, line 98 def search(term) term ||= '' normalized_term = term.downcase.strip indexes = INVERTED_INDEX[normalized_term] indexes ? ISO_639_2.values_at(*indexes).uniq : [] end
Public Instance Methods
The entry's alpha-2 code (when given)
# File lib/iso-639.rb, line 118 def alpha2 self[2] end
The entry's alpha-3 bibliotigraphic code.
# File lib/iso-639.rb, line 107 def alpha3_bibliographic self[0] end
The entry's alpha-3 terminologic (when given)
# File lib/iso-639.rb, line 113 def alpha3_terminologic self[1] end
The entry's english name.
# File lib/iso-639.rb, line 123 def english_name self[3] end
The entry's french name.
# File lib/iso-639.rb, line 128 def french_name self[4] end