Class: I18nChecker::Unused::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_checker/unused/result.rb

Overview

Detection result of unused translated text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unused_texts = []) ⇒ Result

Returns a new instance of Result.

Parameters:



13
14
15
16
# File 'lib/i18n_checker/unused/result.rb', line 13

def initialize(unused_texts = [])
  @unused_texts = unused_texts
  @locale_files = unused_texts.group_by(&:file_name)
end

Instance Attribute Details

#locale_filesHash<String, Array<I18nChecker::Unused::File>> (readonly)

Returns the current value of locale_files.

Returns:

  • (Hash<String, Array<I18nChecker::Unused::File>>)

    the current value of locale_files



7
8
9
# File 'lib/i18n_checker/unused/result.rb', line 7

def locale_files
  @locale_files
end

#unused_textsArray<I18nChecker::Unused::Text> (readonly)

Returns the current value of unused_texts.

Returns:



7
8
9
# File 'lib/i18n_checker/unused/result.rb', line 7

def unused_texts
  @unused_texts
end

Instance Method Details

#apply(target_locale_files) ⇒ Array<I18nChecker::Locale::File>

Apply the detected unused translated text to the current translation file. Unused text has been deleted from the translation file.

Parameters:

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/i18n_checker/unused/result.rb', line 30

def apply(target_locale_files)
  locale_files = target_locale_files.
                   group_by(&:file_name).
                   map { |k, v| [k, v.first] }

  cleanup_locale_files = locale_files.map do |file_name, locale_file|
    return locale_file unless @locale_files.key?(file_name)
    unused_texts = @locale_files[file_name]
    locale_file.remove_texts(unused_texts.map(&:text))
  end
  cleanup_locale_files.each(&:save)
end

#empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/i18n_checker/unused/result.rb', line 21

def empty?
  unused_texts.empty?
end