module Program

Program Utility

Public Class Methods

end( ) click to toggle source

Utility to end the program

# File lib/program.rb, line 109
def self.end( )
  Timer.stop
  output( "Process completed in #{Timer.elapsed}" )
end
get_filenames( directory ) click to toggle source
# File lib/program.rb, line 124
def self.get_filenames( directory )
  output = Array.new
  Dir.glob("#{directory}/*.json") do |file|
    #tmp = file.slice! "#{directory}/"
    output.push(file)
  end
  return output
end
line( ) click to toggle source

Utility method for printing messages.

# File lib/program.rb, line 70
def self.line( )
  puts ( "-" * 62 )
end
output( message ) click to toggle source

Utility method for printing messages.

# File lib/program.rb, line 77
def self.output( message )
  Program.line
  puts " #{message}"
  Program.line
end
read_directory( directory ) click to toggle source
# File lib/program.rb, line 133
def self.read_directory( directory )
  output = Array.new
  Dir.glob("#{directory}/*.json") do |file|
    output.push(Program.read_file(file))
  end
  return output
end
read_file( directory, name ) click to toggle source

Utility method to read output files to a directory.

# File lib/program.rb, line 144
def self.read_file( directory, name )
  return Program.read_file("#{directory}/#{name}")
end
start( name, author, version, date ) click to toggle source

Utility to start the program

# File lib/program.rb, line 86
def self.start( name, author, version, date )
  Timer.start

  Program.line
  puts " #{name} "
  Program.line
  puts " Version: #{version}"
  puts " Date: #{date}"
  puts " Author: #{author}"
  Program.line

  $tenant = nil

  unless $tenant.nil?
    puts " Tenant: #{$tenant}"
    Program.line
  end

end
write_csv(directory, name, content) click to toggle source
# File lib/program.rb, line 159
def self.write_csv(directory, name, content)
  if !File.file?("#{directory}/#{name}")
    Program.write_file(directory, name, "")
  end
  CSV.open("#{directory}/#{name}", "ab") do |csv|
    csv << content
  end
end
write_file( directory, name, text ) click to toggle source

Utility method to write output files to a directory.

# File lib/program.rb, line 118
def self.write_file( directory, name, text )
  name.gsub!(/[^0-9A-Za-z. -]/,"-")
  FileUtils.mkdir_p directory
  File.open( File.join( directory, name ), 'w+') { |file| file.write( text ) }
end