Class: GhSearch::Formatters::Csv

Inherits:
Base
  • Object
show all
Defined in:
lib/gh_search/formatters/csv.rb

Instance Attribute Summary

Attributes inherited from Base

#output_file

Instance Method Summary collapse

Methods inherited from Base

#initialize, #write!

Constructor Details

This class inherits a constructor from GhSearch::Formatters::Base

Instance Method Details

#write(match) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gh_search/formatters/csv.rb', line 6

def write(match)

  if output_file
    @file ||= CSV.open(output_file, "w")
    unless @headers
      @headers = match.keys
      @file << @headers
    end

    @file << match.values
    print_and_flush('.')
  else
    unless @headers
      @headers = match.keys
      puts @headers.join(',')
    end
    puts match.values.join(',')
  end
end

#write_file!Object



26
27
28
# File 'lib/gh_search/formatters/csv.rb', line 26

def write_file!
  @file.close if @file
end