Class: JpStringsFinder::Printer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ Printer

Returns a new instance of Printer.



9
10
11
# File 'lib/jp_strings_finder/printer.rb', line 9

def initialize(list)
  @list = list
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



7
8
9
# File 'lib/jp_strings_finder/printer.rb', line 7

def list
  @list
end

Instance Method Details



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jp_strings_finder/printer.rb', line 13

def print_table
  table = Terminal::Table.new do |t|
    t.headings = ['File', 'Type', 'Strings']
    list.each_with_index do |hash, index|
      t.add_row(
        [
          to_relative_path(Dir.pwd, hash[:file]),
          hash[:type].upcase,
          hash[:strings].join("\n")
        ]
      )
      t.add_separator unless index == list.count - 1
    end
  end
  puts table
  strings_count = list.inject(0) { |acc, elem| acc + elem[:strings].count }
  STDERR.puts "There are #{strings_count} Japanese strings in #{list.count} files".colorize(:yellow)
end