Class: FindT::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/find_t/printer.rb

Constant Summary collapse

COLORS =
{
  black:   0,
  red:     1,
  green:   2,
  yellow:  3,
  blue:    4,
  magenta: 5,
  cyan:    6,
  white:   7,
}

Instance Method Summary collapse

Constructor Details

#initialize(root_path, isatty) ⇒ Printer

Returns a new instance of Printer.



18
19
20
21
# File 'lib/find_t/printer.rb', line 18

def initialize(root_path, isatty)
  @root_path = Pathname.new root_path
  @isatty = isatty
end

Instance Method Details



23
24
25
26
# File 'lib/find_t/printer.rb', line 23

def print_header
  puts 'Starting find_t at %s' % @root_path.to_s
  puts 'Scanning...'
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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