Module: Program
- Defined in:
- lib/program.rb
Overview
Program Utility
Class Method Summary collapse
-
.end ⇒ Object
Utility to end the program.
- .get_filenames(directory) ⇒ Object
-
.line ⇒ Object
Utility method for printing messages.
-
.output(message) ⇒ Object
Utility method for printing messages.
- .read_directory(directory) ⇒ Object
-
.read_file(name) ⇒ Object
Utility method to read output files to a directory.
-
.start(name, author, version, date) ⇒ Object
Utility to start the program.
- .write_csv(directory, name, content) ⇒ Object
-
.write_file(directory, name, text) ⇒ Object
Utility method to write output files to a directory.
Class Method Details
.end ⇒ Object
Utility to end the program
109 110 111 112 |
# File 'lib/program.rb', line 109 def self.end( ) Timer.stop output( "Process completed in #{Timer.elapsed}" ) end |
.get_filenames(directory) ⇒ Object
124 125 126 127 128 129 130 131 |
# 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 ⇒ Object
Utility method for printing messages.
70 71 72 |
# File 'lib/program.rb', line 70 def self.line( ) puts ( "-" * 62 ) end |
.output(message) ⇒ Object
Utility method for printing messages.
77 78 79 80 81 |
# File 'lib/program.rb', line 77 def self.output( ) Program.line puts " #{}" Program.line end |
.read_directory(directory) ⇒ Object
133 134 135 136 137 138 139 |
# 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(name) ⇒ Object
Utility method to read output files to a directory.
144 145 146 |
# File 'lib/program.rb', line 144 def self.read_file( directory, name ) return Program.read_file("#{directory}/#{name}") end |
.start(name, author, version, date) ⇒ Object
Utility to start the program
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/program.rb', line 86 def self.start( name, , version, date ) Timer.start Program.line puts " #{name} " Program.line puts " Version: #{version}" puts " Date: #{date}" puts " Author: #{}" Program.line $tenant = nil unless $tenant.nil? puts " Tenant: #{$tenant}" Program.line end end |
.write_csv(directory, name, content) ⇒ Object
159 160 161 162 163 164 165 166 |
# 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) ⇒ Object
Utility method to write output files to a directory.
118 119 120 121 122 |
# 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 |