Class: I18n::Coverage::Printers::FilePrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/coverage/printers/file_printer.rb

Constant Summary collapse

REPORT_PATH =
'coverage/i18n.json'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ FilePrinter

Returns a new instance of FilePrinter.



11
12
13
# File 'lib/i18n/coverage/printers/file_printer.rb', line 11

def initialize(report)
  @report = report
end

Class Method Details



7
8
9
# File 'lib/i18n/coverage/printers/file_printer.rb', line 7

def self.print(report)
  new(report).print
end

Instance Method Details



15
16
17
18
# File 'lib/i18n/coverage/printers/file_printer.rb', line 15

def print
  write_report
  print_message
end


25
26
27
28
29
# File 'lib/i18n/coverage/printers/file_printer.rb', line 25

def print_message
  puts "Coverage report generated for I18n to #{REPORT_PATH}. " \
    "#{@report[:used_key_count]} / #{@report[:key_count]} keys " \
    "(#{@report[:percentage_used].round(2)}%) covered."
end

#write_reportObject



20
21
22
23
# File 'lib/i18n/coverage/printers/file_printer.rb', line 20

def write_report
  FileUtils.mkdir_p(File.dirname(REPORT_PATH))
  File.write(REPORT_PATH, JSON.pretty_generate(@report))
end