Class: Validator::FileValidator
- Inherits:
-
Object
- Object
- Validator::FileValidator
- Defined in:
- lib/mylookup/validator.rb
Overview
File Validator to validate the input paths of a file
Instance Method Summary collapse
-
#initialize(path, coll: '') ⇒ FileValidator
constructor
A new instance of FileValidator.
- #validate ⇒ Object
Constructor Details
#initialize(path, coll: '') ⇒ FileValidator
Returns a new instance of FileValidator.
58 59 60 61 |
# File 'lib/mylookup/validator.rb', line 58 def initialize(path, coll: '') @path = path @coll = coll end |
Instance Method Details
#validate ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 |