Module: GhSearch::Formatters

Defined in:
lib/gh_search/formatters.rb,
lib/gh_search/formatters/csv.rb,
lib/gh_search/formatters/base.rb,
lib/gh_search/formatters/json.rb,
lib/gh_search/formatters/plain.rb

Defined Under Namespace

Classes: Base, Csv, Json, Plain

Class Method Summary collapse

Class Method Details

.with(type, options = {}) {|formatter| ... } ⇒ Object

Yields:

  • (formatter)


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

def self.with(type, options={})
  formatter_class = case type
              when 'plain'
                Formatters::Plain
              when 'csv'
                Formatters::Csv
              when 'json'
                Formatters::Json
              when 'stdout'
                Formatters::Stdout
              else
                raise 'unknown format type'
              end

  # puts "[DEBUG] Loaded #{formatter_class.name}"
  formatter = formatter_class.new(options)
  yield formatter

  formatter.write_file!
  puts
end