Sha256: 5eda8a95cb0a69ef22c646f3eb46bbe09168ff77da4f253a47d9343f421f7d97

Contents?: true

Size: 884 Bytes

Versions: 2

Compression:

Stored size: 884 Bytes

Contents

require 'hscode/version'
require 'hscode/input_parser'
require 'hscode/http_status_codes'
require 'optparse'
require 'ostruct'

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

    private_class_method

    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
      end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hscode-0.1.1 lib/hscode.rb
hscode-0.1.0 lib/hscode.rb