Class: I18nChecker::Unused::Result
- Inherits:
-
Object
- Object
- I18nChecker::Unused::Result
- Defined in:
- lib/i18n_checker/unused/result.rb
Overview
Detection result of unused translated text
Instance Attribute Summary collapse
-
#locale_files ⇒ Hash<String, Array<I18nChecker::Unused::File>>
readonly
The current value of locale_files.
-
#unused_texts ⇒ Array<I18nChecker::Unused::Text>
readonly
The current value of unused_texts.
Instance Method Summary collapse
-
#apply(target_locale_files) ⇒ Array<I18nChecker::Locale::File>
Apply the detected unused translated text to the current translation file.
- #empty? ⇒ Boolean
-
#initialize(unused_texts = []) ⇒ Result
constructor
A new instance of Result.
Constructor Details
#initialize(unused_texts = []) ⇒ Result
Returns a new instance of Result.
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_files ⇒ Hash<String, Array<I18nChecker::Unused::File>> (readonly)
Returns 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_texts ⇒ Array<I18nChecker::Unused::Text> (readonly)
Returns the current value of unused_texts.
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.
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
21 22 23 |
# File 'lib/i18n_checker/unused/result.rb', line 21 def empty? unused_texts.empty? end |