Skip to content

Commit

Permalink
faster regex validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishnaprasad T Nair committed Jan 15, 2013
1 parent 4c66a5a commit e244bbc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/mobme_support/core_ext/string/msisdn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ def msisdn(options_hash = {})
# "+919846819033".msisdn?(:country => 'CA')
# false
def msisdn?(options_hash = {})
msisdn(options_hash) ? true : false
default_options = {
:country => 'IN',
:format => 'local'
}
options_hash = options_hash.symbolize_keys.reverse_merge(default_options)
@@msdn_format_data ||= YAML.load_file(File.dirname(__FILE__) + "/msisdn_formats.yml")
msisdn_format = @@msdn_format_data[options_hash[:country]]
self =~ msisdn_format['regexp']
end
end
end
Expand Down

0 comments on commit e244bbc

Please sign in to comment.