class Gaigo::Langs

Public Instance Methods

add_lang(attributes) click to toggle source
# File lib/gaigo/langs.rb, line 23
def add_lang(attributes)
  self << Lang.new(*attributes)
end
codes() click to toggle source
# File lib/gaigo/langs.rb, line 47
def codes
  self.map {|i| i.code}
end
copy(*locale_codes) click to toggle source
# 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() click to toggle source
# File lib/gaigo/langs.rb, line 51
def en
  self.map {|i| i.en}
end
get(code) click to toggle source
# File lib/gaigo/langs.rb, line 27
def get(code)
  self.find {|i| i.code == code.to_s}
end
get_by_en(name) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/gaigo/langs.rb, line 55
def native
  self.map {|i| i.native}
end
validate_codes(*args) click to toggle source
# File lib/gaigo/langs.rb, line 59
def validate_codes(*args)
  options = args.extract_options!
  codes = self.codes
  args.map(&:to_s).select do |code|
    if code.to_s.in?(codes)
      true
    else
      options[:raise] == true ? raise(Exception, "Invalid code: :#{code}") : false
    end
  end
end