Class: Gawk::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(config_file: '.gawk.yaml', report_key: nil, engine: Gawk::Engine.new) ⇒ CLI

Returns a new instance of CLI.



6
7
8
9
10
# File 'lib/gawk/cli.rb', line 6

def initialize(config_file: '.gawk.yaml', report_key: nil, engine: Gawk::Engine.new)
  @config_file = config_file
  @report_key = report_key
  @engine = engine
end

Instance Method Details

#get_data_from_config_file(data_type) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/gawk/cli.rb', line 20

def get_data_from_config_file(data_type)
  data = []
  if @report_key
    data << load_config_file.dig(@report_key, data_type)
  else
    load_config_file.each {|k, v| data << v.fetch(data_type) }
  end
  data
end

#outputObject



12
13
14
15
16
17
18
# File 'lib/gawk/cli.rb', line 12

def output
  requests = get_data_from_config_file('request')
  tables = get_data_from_config_file('table')
  @engine.get_reports(requests).each.with_index do |report, i|
    puts generate_table(tables[i], requests, report).to_s
  end
end