Class: CertOpenDataVisualizer::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



5
6
7
# File 'lib/cert_open_data_visualizer/cli.rb', line 5

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



3
4
5
# File 'lib/cert_open_data_visualizer/cli.rb', line 3

def argv
  @argv
end

Instance Method Details

#helpObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cert_open_data_visualizer/cli.rb', line 35

def help
  puts <<EOF
CertOpenDataVisualizer
Commands are:
  first  - prints results in format required for first print
  second - prints results in format required for second print
  help   - shows this
  clean  - cleanes cache
  fetch  - fetches new data if neccessary
  app    - launces web server for visualizations in http://127.0.0.1:4567
  city   - `city hel` - list details for each city containing `hel`

Commands may download and parse data when neccesary.

A file cache is utilised for faster results.
ie. information is calculated only when necessary, and cached for
further use. Cache may be cleared using `clean`
EOF
end


55
56
57
# File 'lib/cert_open_data_visualizer/cli.rb', line 55

def print_version
  puts CertOpenDataVisualizer::VERSION
end

#run_appObject



59
60
61
# File 'lib/cert_open_data_visualizer/cli.rb', line 59

def run_app
  CertOpenDataVisualizer::Frontend::App.run!
end

#startObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cert_open_data_visualizer/cli.rb', line 9

def start
  visualizer = CertDataVisualizer.new
  commands = {fetch: "fetch!",
              clean: "clean_cache!",
              crear: "clean_cache!",
              first: "print_first_format",
              second: "print_second_format",
              app: "start-app",
              city: "filter_by_city",
              v: "version",
              version: "version",
              help: "print_help"}

  return help if @argv[0].nil?
  command = @argv.shift.to_sym

  exec = commands[command]

  return run_app if exec == "start-app"
  return print_version if exec == "version"
  return help if exec == "print_help"
  return visualizer.send(exec, *argv) if exec
  puts "Invalid command #{command}"
end