2020-03-26 11:21:59 +00:00
|
|
|
module PincodeValidator
|
2023-07-02 09:20:25 +00:00
|
|
|
VERSION = "2.0.0"
|
2020-04-26 02:43:44 +00:00
|
|
|
FILENAME='regex.txt'
|
|
|
|
|
2020-03-26 11:21:59 +00:00
|
|
|
class Error < StandardError; end
|
2020-04-26 02:43:44 +00:00
|
|
|
|
|
|
|
def self.root
|
|
|
|
File.dirname __dir__
|
|
|
|
end
|
|
|
|
|
2023-07-01 14:30:02 +00:00
|
|
|
@@regex ||=
|
|
|
|
Regexp.new(File.read(File.join root, FILENAME).strip)
|
|
|
|
|
|
|
|
@@exactRegex ||=
|
|
|
|
Regexp.new("^#{File.read(File.join root, FILENAME).strip}$")
|
2020-04-26 02:43:44 +00:00
|
|
|
|
|
|
|
def self.valid?(pincode)
|
2023-07-01 14:30:02 +00:00
|
|
|
return true if @@exactRegex.match? pincode
|
2020-04-26 02:43:44 +00:00
|
|
|
false
|
|
|
|
end
|
2023-07-01 14:30:02 +00:00
|
|
|
|
|
|
|
def self.search?(address)
|
|
|
|
address.scan(@@regex).map(&:first).map(&:strip)
|
|
|
|
end
|
2020-03-26 11:21:59 +00:00
|
|
|
end
|