Class: Lokale::Reporter
- Inherits:
-
Object
- Object
- Lokale::Reporter
- Defined in:
- lib/lokale/reporter.rb
Instance Method Summary collapse
-
#initialize(agent) ⇒ Reporter
constructor
A new instance of Reporter.
- #print_diferences_report ⇒ Object
- #print_files_table ⇒ Object
- #print_macro_calls_summary ⇒ Object
- #print_macro_table ⇒ Object
- #print_repeats_report ⇒ Object
- #print_summary ⇒ Object
Constructor Details
#initialize(agent) ⇒ Reporter
Returns a new instance of Reporter.
3 4 5 |
# File 'lib/lokale/reporter.rb', line 3 def initialize(agent) @agent = agent end |
Instance Method Details
#print_diferences_report ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/lokale/reporter.rb', line 71 def print_diferences_report diferences_repot = "" @agent.lfiles.group_by { |f| f.full_name }.each do |file_name, files| base_lang = files.any? { |f| f.lang == "Base" } ? "Base" : "en" files = files.select { |f| f.lang != base_lang } all_keys = files.map(&:keys).compact.map(&:to_set) next if all_keys.empty? united_keys = all_keys.reduce(:|) all_keys.map! { |ks| united_keys - ks } next if all_keys.map(&:length).reduce(:+).zero? diferences_repot << "Missing keys in file \"#{file_name}\":\n" all_keys.zip(files) do |missing_keys, lfile| next if missing_keys.size.zero? diferences_repot << "*".red + " #{lfile.lang} - #{missing_keys.size} key(s):\n" missing_keys.each { |k| diferences_repot << "#{k}\n" } end diferences_repot << "\n" end if diferences_repot.empty? puts "Localization files are full.".green puts else puts "Localization files are not full.".red puts diferences_repot puts end end |
#print_files_table ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lokale/reporter.rb', line 23 def print_files_table languages = @agent.lfiles.map { |e| e.lang }.to_set.to_a files = @agent.lfiles.map { |e| e.full_name }.to_set.to_a puts "Found #{@agent.lfiles.size} localized files for #{languages.size} languages." description_header = "[*]".rpadded(36) languages.each { |l| description_header << l.rpadded(8) } puts description_header files.each do |f| description_string = f.rpadded(36) languages.each do |l| lfile = @agent.lfiles.select { |lf| lf.full_name == f && lf.lang == l } description_string << (lfile.empty? ? "-" : lfile[0].parsed.nil? ? "*" : "#{lfile[0].parsed.size}").rpadded(8) end puts description_string end puts end |
#print_macro_calls_summary ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/lokale/reporter.rb', line 15 def print_macro_calls_summary total_macro_calls = @agent.macros.map(&:total_count).reduce(:+) uniq_macro_calls = @agent.macros.map(&:uniq_count).reduce(:+) puts "Found #{total_macro_calls} localization macro calls in #{@agent.sfiles_proceeded} files." puts "Uniq macro calls: #{uniq_macro_calls}" puts end |
#print_macro_table ⇒ Object
44 45 46 47 48 49 |
# File 'lib/lokale/reporter.rb', line 44 def print_macro_table @agent.macros.each do |macro| puts "#{macro.name}:".rpadded(24) + "total: #{macro.total_count}".rpadded(16) + "uniq: #{macro.uniq_count}" end puts end |
#print_repeats_report ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lokale/reporter.rb', line 51 def print_repeats_report repeats_repot = "" @agent.lfiles.each do |lf| repeats = lf.repeats next if repeats.count.zero? repeats_repot << "#{lf.lang}/#{lf.full_name} repeats:\n" repeats_repot << repeats.join("\n") repeats_repot << "\n" end if repeats_repot.empty? puts "Repeats not found.".green puts else puts "Found repeats in strings files.".red puts repeats_repot puts end end |
#print_summary ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/lokale/reporter.rb', line 7 def print_summary print_macro_calls_summary print_macro_table print_files_table print_repeats_report print_diferences_report end |