Skip to content

Commit

Permalink
Add ability to search by ISO-639-2b and ISO-639-2t codes
Browse files Browse the repository at this point in the history
  • Loading branch information
mainameiz committed Dec 5, 2016
1 parent 07288b2 commit ae3dd06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Binary file modified data/dump
Binary file not shown.
22 changes: 20 additions & 2 deletions lib/language_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

module LanguageList
class LanguageInfo
attr_reader :name, :iso_639_3, :iso_639_1, :type
attr_reader :name, :iso_639_3, :iso_639_1, :iso_639_2b, :iso_639_2t, :type

def initialize(options)
@name = options[:name]
@common_name = options[:common_name]
@iso_639_3 = options[:iso_639_3]
@iso_639_1 = options[:iso_639_1]
@iso_639_2b = options[:iso_639_2b]
@iso_639_2t = options[:iso_639_2t]
@common = options[:common]
@type = options[:type]
end
Expand Down Expand Up @@ -47,13 +49,25 @@ def self.find_by_iso_639_3(code)
LanguageList::BY_ISO_639_3[code]
end

def self.find_by_iso_639_2b(code)
LanguageList::BY_ISO_639_2B[code]
end

def self.find_by_iso_639_2t(code)
LanguageList::BY_ISO_639_2T[code]
end

def self.find_by_name(name)
LanguageList::BY_NAME[name.downcase]
end

def self.find(code)
code.downcase!
find_by_iso_639_1(code) || find_by_iso_639_3(code) || find_by_name(code)
find_by_iso_639_1(code) ||
find_by_iso_639_3(code) ||
find_by_iso_639_2b(code) ||
find_by_iso_639_2t(code) ||
find_by_name(code)
end
end

Expand All @@ -71,10 +85,14 @@ def self.find(code)
BY_NAME = {}
BY_ISO_639_1 = {}
BY_ISO_639_3 = {}
BY_ISO_639_2B = {}
BY_ISO_639_2T = {}
ALL_LANGUAGES.each do |lang|
BY_NAME[lang.name.downcase] = lang
BY_ISO_639_1[lang.iso_639_1] = lang if lang.iso_639_1
BY_ISO_639_3[lang.iso_639_3] = lang if lang.iso_639_3
BY_ISO_639_2B[lang.iso_639_2b] = lang if lang.iso_639_2b
BY_ISO_639_2T[lang.iso_639_2t] = lang if lang.iso_639_2t
end

end

0 comments on commit ae3dd06

Please sign in to comment.