Class: Lokale::Exporter::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/lokale/agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(main_files, lfiles, lang) ⇒ Diff

Returns a new instance of Diff.



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/lokale/agent.rb', line 285

def initialize(main_files, lfiles, lang)
  @lang = lang
  @missing_strings = Hash.new { |h, k| h[k] = [] }
  lfiles.each do |lf|
    next unless lf.strings_file?
    counterpart = main_files.select { |m| m.full_name == lf.full_name }.sample
    next if counterpart.nil?

    missing_keys = counterpart.keys - lf.keys
    next if missing_keys.empty?

    counterpart.parsed.each do |lstr|
      next unless missing_keys.include? lstr.key 
      @missing_strings[lf.full_name] << lstr.for_export(lang)
    end
  end
end

Instance Attribute Details

#langObject (readonly)

Returns the value of attribute lang.



272
273
274
# File 'lib/lokale/agent.rb', line 272

def lang
  @lang
end

#missing_stringsObject (readonly)

Returns the value of attribute missing_strings.



272
273
274
# File 'lib/lokale/agent.rb', line 272

def missing_strings
  @missing_strings
end

Class Method Details

.find(files, main_lang) ⇒ Object



274
275
276
277
278
279
280
281
282
283
# File 'lib/lokale/agent.rb', line 274

def self.find(files, main_lang)
  groups = files.group_by { |lf| lf.lang }
  main_files = groups[main_lang]
  diffs = []
  groups.each do |lang, files|
    next if lang == main_lang
    diffs << Diff.new(main_files, files, lang)
  end
  diffs.delete_if { |d| d.empty? }
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


303
304
305
# File 'lib/lokale/agent.rb', line 303

def empty?
  @missing_strings.empty? || @missing_strings.all? { |file_name, strings| strings.empty? }
end