Class: Hscode::CliController

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

Class Method Summary collapse

Class Method Details

.call(args) ⇒ Object



10
11
12
13
# File 'lib/hscode.rb', line 10

def self.call(args)
  options = Hscode::InputParser.new.parse(args)
  print_code(options)
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hscode.rb', line 17

def self.print_code(options)
  status_code = HTTP_STATUS_CODES[options.status_code.to_i]

  unless status_code
    puts "#{options.status_code} is not a valid code. See 'hscode --help'."
    exit 1
  end

  PrettyPrint.print(
    "#{options.status_code} - #{status_code[:title]}",
    options.status_code.to_s[0]
  )
  print_description(status_code) if options.verbose
end


32
33
34
35
36
# File 'lib/hscode.rb', line 32

def self.print_description(status_code)
  status_code[:description].each do |desc|
    PrettyPrint.print("\n#{desc}", '0')
  end
end