HiveBrain v1.2.0
Get Started
← Back to all entries
patternrubyMinor

Command line based email generation tool

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
emaillinegenerationbasedcommandtool

Problem

Unfortunately due to my job I will have to leave out some of the information that is created by this generator, however I will be replacing it with another string of information.

I have created an email generator for work, that will user a template and add the information provided into the email, I would like some critique on what I've done so far I will not be able to add a GitHub repository for this program, so I understand if you do not want to take the time to look through the code, thank you ahead of time.

Main file:

```
#!/usr/local/bin/env ruby

require 'date'
require 'etc'

require_relative 'lib/clipboard'
require_relative 'lib/date'
require_relative 'lib/format'
require_relative 'lib/time'
require_relative 'lib/email/version'
require_relative 'lib/log_email'

include Format
include DateCheck
include TimeCheck
include ClipBrd
include Email
include LogEmail

def help_page
#-
# Basic help for the program
#-#

puts
"\e[44mruby gen_email.rb -[t] --[example|version|dev-mode]\e[0m"
end

def examples_page
#-
# Shows an example of a generic email that was created by the program
#-#


# If the user has a PATH that is used as their editor
# The program will open the source file in that editor
# other wise it opens the source file in notepad
#-#

ENV['editor'].nil? ? system('notepad.exe gen_email.rb') : system(ENV['editor'])
end

def header
TimeCheck.check_time
end

def name
Format.prompt('Enter users full name')
end

def summary
Format.prompt('Enter summary of issue')
end

def num
Format.prompt('Enter ticket number')
end

def body
Format.prompt('Enter what will happen or what you did')
end

def check_date
DateCheck.date
end

def account
Format.prompt('Enter users account')
end

def get_user
#-
# Get the name by using the Etc library,
# basically just pull the login name and
# grab the first word along with the first
# letter of the last word
#-#

user = Etc.getlogin
@esd_user = user.split('_').first.ca

Solution

Have you considered using OptionParser or GLI? Both provide utilities to easily make a command line application.

I'd suggest moving the email templates out to separate files, perhaps with ERb. That way, the presentation is separated from the business logic of this tool.

Instead of having everything in modules and #includeing them into the main global Object, I would consider moving this functionality to one or more classes that can be instantiated in this script. This will make it easier to test your code.

Context

StackExchange Code Review Q#128126, answer score: 3

Revisions (0)

No revisions yet.