Class: Extractor
- Inherits:
-
Object
- Object
- Extractor
- Defined in:
- lib/extractor.rb
Instance Method Summary collapse
- #get_directory(args) ⇒ Object
- #op_file(dir, options) ⇒ Object
- #perform(options, args) ⇒ Object
- #show_error(msg, e) ⇒ Object
- #show_throughput(msg, verbose) ⇒ Object
Instance Method Details
#get_directory(args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/extractor.rb', line 33 def get_directory(args) begin case args.count when 0 Dir.pwd when 1 File.absolute_path(args.first) else raise ArgumentError, 'Arguments limit breached' end rescue ArgumentError => e show_error('Unable to set directory', e) end end |
#op_file(dir, options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/extractor.rb', line 48 def op_file(dir,) begin attr_labels = %w[directory file_name latitude longitude] dir_name = File.basename(dir) if [:html] Template::Html.new(dir_name, attr_labels) else Template::Csv.new(dir_name, attr_labels) end rescue SystemCallError => e STDERR.puts 'Unable to initialize the output file' STDERR.puts 'Make sure you have write permission to your pwd' if [:html] STDERR.puts 'If you have not installed the gem, check your config file' end STDERR.puts e. exit end end |
#perform(options, args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/extractor.rb', line 8 def perform(, args) show_throughput('Setting directory', [:verbose]) dir = get_directory(args) show_throughput('Create output file', [:verbose]) output_file = op_file(dir, ) begin show_throughput('Scan Started', [:verbose]) FileScanner.new(dir, output_file, [:verbose]).begin_scan rescue SystemCallError => e show_error('Unable to scan this directory', e) rescue StandardError => e show_error('', e) end show_throughput('Scan Completed', [:verbose]) show_throughput('Finalising O/P File', [:verbose]) output_file.close show_throughput('Exit', [:verbose]) show_throughput("OutPut Recorded in file: #{output_file.file_name}", true) exit end |
#show_error(msg, e) ⇒ Object
73 74 75 76 77 |
# File 'lib/extractor.rb', line 73 def show_error(msg, e) STDERR.puts msg STDERR.puts e. exit end |
#show_throughput(msg, verbose) ⇒ Object
69 70 71 |
# File 'lib/extractor.rb', line 69 def show_throughput(msg, verbose) puts msg if verbose end |