class Validator::FileValidator
File Validator
to validate the input paths of a file¶ ↑
Public Class Methods
new(path, coll: '')
click to toggle source
# File lib/mylookup/validator.rb, line 58 def initialize(path, coll: '') @path = path @coll = coll end
Public Instance Methods
validate()
click to toggle source
# File lib/mylookup/validator.rb, line 63 def validate if is_excel_file if excel_file_exists [true, "#{@path} does exist"] else return [false, "#{@path} does not exist"] end else if @path =~ /\./i return false, "#{@path} is neither an excel file nor a MongoDB collection" else db = File.split(@path)[1] mongo_conn = Connector::MongoConnector.new(@coll, db_name: db) unless mongo_conn.collection_exists? return [false, "'#{@path}' collection in MongoDB does not exist"] else return true, "'#{@path}' is a MongoDB collection" end end end end
Private Instance Methods
excel_file_exists()
click to toggle source
# File lib/mylookup/validator.rb, line 85 def excel_file_exists File.file?(@path) end
is_excel_file()
click to toggle source
# File lib/mylookup/validator.rb, line 89 def is_excel_file @path[-5, 5] == '.xlsx' end