india-pincode-regex/src/pincode_validator.rb

26 lines
491 B
Ruby
Raw Permalink Normal View History

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
@@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)
return true if @@exactRegex.match? pincode
2020-04-26 02:43:44 +00:00
false
end
def self.search?(address)
address.scan(@@regex).map(&:first).map(&:strip)
end
2020-03-26 11:21:59 +00:00
end