class FindT::Printer
Constants
- COLORS
Public Class Methods
new(root_path, isatty)
click to toggle source
# File lib/find_t/printer.rb, line 18 def initialize(root_path, isatty) @root_path = Pathname.new root_path @isatty = isatty end
Public Instance Methods
print_header()
click to toggle source
# File lib/find_t/printer.rb, line 23 def print_header puts 'Starting find_t at %s' % @root_path.to_s puts 'Scanning...' end
print_results(founds)
click to toggle source
# File lib/find_t/printer.rb, line 28 def print_results(founds) unless founds.any? print_empty return end founds .reverse .group_by { |f| f[:locale] } .sort_by { |f| f[0] } .each do |(locale, locale_founds)| print_title locale locale_founds.each.with_index do |found, i| print_translation found, i.zero? end end end
Private Instance Methods
color(str, c)
click to toggle source
# File lib/find_t/printer.rb, line 77 def color(str, c) @isatty ? "\e[1;%dm%s\e[0m" % [30 + COLORS[c], str] : str end
print_empty()
click to toggle source
# File lib/find_t/printer.rb, line 47 def print_empty puts puts color("Can't find translation for the key", :red) end
print_title(title)
click to toggle source
# File lib/find_t/printer.rb, line 52 def print_title(title) puts puts color('==> %s' % title, :yellow) puts end
print_translation(found, conflicted)
click to toggle source
# File lib/find_t/printer.rb, line 58 def print_translation(found, conflicted) text = printable_text found[:text] file = relative_path found[:file] puts <<-EOS - #{file}:#{found[:line]}#{conflicted ? '' : ' [CONFLICTED]'} #{color(text, :green)} EOS end
printable_text(text)
click to toggle source
# File lib/find_t/printer.rb, line 68 def printable_text(text) (text == '') ? '{ ... }' : text end
relative_path(file)
click to toggle source
# File lib/find_t/printer.rb, line 72 def relative_path(file) return file unless @root_path Pathname.new(file).relative_path_from(@root_path).to_s end