Class: Gaigo::Langs
- Inherits:
-
Array
- Object
- Array
- Gaigo::Langs
- Defined in:
- lib/gaigo/langs.rb
Defined Under Namespace
Classes: Lang
Instance Method Summary collapse
- #add_lang(attributes) ⇒ Object
- #codes ⇒ Object
- #copy(*locale_codes) ⇒ Object
- #en ⇒ Object
- #get(code) ⇒ Object
- #get_by_en(name) ⇒ Object
- #get_by_method(method) ⇒ Object
- #get_by_name(name) ⇒ Object
- #get_by_native(name) ⇒ Object
- #native ⇒ Object
- #validate_codes(*args) ⇒ Object
Instance Method Details
#add_lang(attributes) ⇒ Object
23 24 25 |
# File 'lib/gaigo/langs.rb', line 23 def add_lang(attributes) self << Lang.new(*attributes) end |
#codes ⇒ Object
47 48 49 |
# File 'lib/gaigo/langs.rb', line 47 def codes self.map {|i| i.code} end |
#copy(*locale_codes) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gaigo/langs.rb', line 71 def copy(*locale_codes) if locale_codes.any? Langs.new.tap do |new_langs| locale_codes.each do |code| new_langs << get(code.to_s) end end else self.dup end end |
#en ⇒ Object
51 52 53 |
# File 'lib/gaigo/langs.rb', line 51 def en self.map {|i| i.en} end |
#get(code) ⇒ Object
27 28 29 |
# File 'lib/gaigo/langs.rb', line 27 def get(code) self.find {|i| i.code == code.to_s} end |
#get_by_en(name) ⇒ Object
39 40 41 |
# File 'lib/gaigo/langs.rb', line 39 def get_by_en(name) self.find {|i| i.en.downcase == name.downcase.to_s} end |
#get_by_method(method) ⇒ Object
31 32 33 |
# File 'lib/gaigo/langs.rb', line 31 def get_by_method(method) self.find {|i| i.to_method == method.to_s} end |
#get_by_name(name) ⇒ Object
43 44 45 |
# File 'lib/gaigo/langs.rb', line 43 def get_by_name(name) get_by_native(name)||get_by_english(name) end |
#get_by_native(name) ⇒ Object
35 36 37 |
# File 'lib/gaigo/langs.rb', line 35 def get_by_native(name) self.find {|i| i.native.mb_chars.downcase.to_s == name.encode('UTF-8').mb_chars.downcase.to_s} end |
#native ⇒ Object
55 56 57 |
# File 'lib/gaigo/langs.rb', line 55 def native self.map {|i| i.native} end |
#validate_codes(*args) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gaigo/langs.rb', line 59 def validate_codes(*args) = args. codes = self.codes args.map(&:to_s).select do |code| if code.to_s.in?(codes) true else [:raise] == true ? raise(Exception, "Invalid code: :#{code}") : false end end end |