Module: I18nLocales

Extended by:
I18nLocales
Included in:
I18nLocales
Defined in:
lib/i18n_locales.rb,
lib/i18n_locales/version.rb

Defined Under Namespace

Classes: Pair

Constant Summary collapse

VERSION =
'0.0.1'

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.formatObject

Returns the value of attribute format.



17
18
19
# File 'lib/i18n_locales.rb', line 17

def format
  @format
end

Instance Method Details

#allObject



21
22
23
# File 'lib/i18n_locales.rb', line 21

def all
  where
end

#match_country(country, find_by_country = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/i18n_locales.rb', line 25

def match_country(country, find_by_country=nil)
  if find_by_country.is_a? Array
    find_by_country.map(&:downcase).include? country.downcase
  elsif find_by_country.is_a? String
    $stderr.puts "find_by_country=#{find_by_country} #{find_by_country.class}  == #{country} #{country.class}"
    find_by_country.downcase == country.downcase
  else
    true
  end
end

#match_language(language, find_by_language = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/i18n_locales.rb', line 36

def match_language(language, find_by_language=nil)
  if find_by_language.is_a? Array
    find_by_language.map(&:upcase).include? language.upcase
  elsif find_by_language.is_a? String
    find_by_language.upcase == language.upcase
  else
    true
  end
end

#rawObject



6
7
8
# File 'lib/i18n_locales.rb', line 6

def raw
  @@raw ||= YAML.load_file('data/pairs.yaml')
end

#where(find_by_language = nil, find_by_country = nil, with_format = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/i18n_locales.rb', line 46

def where(find_by_language=nil, find_by_country=nil, with_format=nil)
  raw.map { |country, languages|
    next unless match_country(country, find_by_country)
    languages.map { |language|
      next unless match_language(language, find_by_language)
      Pair.new(country, language, with_format)
    }.compact unless languages.nil?
  }.flatten.compact
end