#!/usr/bin/env ruby require 'optparse' require 'punctuation_name' # -------------------------------------------------------------------------------- # # Send Mssage to Slack # # -------------------------------------------------------------------------------- # # This function will take the input arguments and then send the message. # # -------------------------------------------------------------------------------- # def punctuation_name(options) pn = PunctuationName.new if options[:dictionary] puts pn.name(options[:punctuation], options[:dictionary]) else puts pn.name(options[:punctuation]) end end # -------------------------------------------------------------------------------- # # Process Arguments # # -------------------------------------------------------------------------------- # # This function will process the input from the command line and work out what it # # is that the user wants to see. # # # # This is the main processing function where all the processing logic is handled. # # -------------------------------------------------------------------------------- # def process_arguments options = {} # Enforce the presence of mandatory = %I[punctuation] optparse = OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($PROGRAM_NAME)}" opts.on('-h', '--help', 'Display this screen') do puts opts exit(1) end opts.on('-d', '--dictionary string', 'The dictionary to us') do |dictionary| options[:dictionary] = dictionary end opts.on('-p', '--punctuation string', 'The punctuation to lookup') do |punctuation| options[:punctuation] = punctuation end end begin optparse.parse! missing = mandatory.select { |param| options[param].nil? } raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty? rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e puts e.to_s puts optparse exit(1) end punctuation_name(options) end # -------------------------------------------------------------------------------- # # Main() # # -------------------------------------------------------------------------------- # # The main function where all of the heavy lifting and script config is done. # # -------------------------------------------------------------------------------- # def main process_arguments end main # -------------------------------------------------------------------------------- # # End of Script # # -------------------------------------------------------------------------------- # # This is the end - nothing more to see here. # # -------------------------------------------------------------------------------- #