Class: Clean::Locales::Scrutator

Inherits:
Object
  • Object
show all
Defined in:
lib/clean/locales.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScrutator

Returns a new instance of Scrutator.


6
7
8
9
# File 'lib/clean/locales.rb', line 6

def initialize
  @to_translate = 0
  @untranslated = 0
end

Instance Attribute Details

#to_translateObject (readonly)

Returns the value of attribute to_translate


4
5
6
# File 'lib/clean/locales.rb', line 4

def to_translate
  @to_translate
end

#untranslatedObject (readonly)

Returns the value of attribute untranslated


4
5
6
# File 'lib/clean/locales.rb', line 4

def untranslated
  @untranslated
end

Instance Method Details

#exp(hash, *keys) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/clean/locales.rb', line 11

def exp(hash, *keys)
  options = keys.extract_options!
  name = keys.last
  @to_translate += 1
  value = rec(hash, *keys)
  yaml = Clean::Support.pair_to_yaml(name, value || options[:default] || name.to_s.humanize)
  unless value
    @untranslated += 1
    yaml.gsub!(/^/, Clean::Support.missing_prompt)
  end
  yaml
end

#rec(hash, *keys) ⇒ Object


24
25
26
27
28
29
30
31
# File 'lib/clean/locales.rb', line 24

def rec(hash, *keys)
  key = keys.first
  if hash.is_a?(Hash)
    return rec(hash[key], *keys[1..-1]) if keys.count > 1
    return hash[key]
  end
  nil
end