Class: I18n::MissingTranslations::Log
- Inherits:
-
Hash
- Object
- Hash
- I18n::MissingTranslations::Log
- Defined in:
- lib/i18n/missing_translations/log.rb
Instance Method Summary collapse
- #dump(out = $stdout) ⇒ Object
- #log(keys) ⇒ Object
- #read(filename) ⇒ Object
- #to_yml ⇒ Object
- #write(filename) ⇒ Object
Instance Method Details
#dump(out = $stdout) ⇒ Object
13 14 15 |
# File 'lib/i18n/missing_translations/log.rb', line 13 def dump(out = $stdout) out.puts(to_yml) unless empty? end |
#log(keys) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/i18n/missing_translations/log.rb', line 6 def log(keys) keys = keys.dup key = keys.pop.to_s log = keys.inject(self) { |log, k| log.key?(k.to_s) ? log[k.to_s] : log[k.to_s] = {} } log[key] = key.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } end |
#read(filename) ⇒ Object
17 18 19 |
# File 'lib/i18n/missing_translations/log.rb', line 17 def read(filename) self.replace(YAML.load_file(filename)) rescue nil end |
#to_yml ⇒ Object
25 26 27 |
# File 'lib/i18n/missing_translations/log.rb', line 25 def to_yml YAML.dump(Hash[*to_a.flatten]).split("\n").map(&:rstrip).join("\n") end |
#write(filename) ⇒ Object
21 22 23 |
# File 'lib/i18n/missing_translations/log.rb', line 21 def write(filename) File.open(filename, 'w+') { |f| f.write(to_yml) } unless empty? end |