Class: Gemat::Formatter

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

Direct Known Subclasses

CsvFormatter, MdFormatter, OrgFormatter

Instance Method Summary collapse

Constructor Details

#initialize(gems, columns, write_path: nil) ⇒ Formatter

Returns a new instance of Formatter.



5
6
7
8
9
10
11
12
# File 'lib/formatter.rb', line 5

def initialize(gems, columns, write_path: nil)
  @gems = gems
  @columns = columns
  @write_path = write_path
  @rows = []
  set_column_name_length
  gen_rows
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/formatter.rb', line 14

def run
  if @write_path
    File.open(@write_path, 'w') do |file|
      each_write(@rows) { |string| file << string }
    end
  else
    print "\n\n"
    each_write(@rows) { |string| print string }
    print "\n"
  end
end