Module: MobME::Infrastructure::Utilities::CoreExtensions::MSISDN
- Included in:
- String
- Defined in:
- lib/mobme_support/core_ext/string/msisdn.rb
Overview
String extension, which allows MSISDN validation.
Instance Method Summary collapse
-
#msisdn(options_hash = {}) ⇒ String?
Validates and converts an MSISDN in the string to the required format.
-
#msisdn?(options_hash = {}) ⇒ Boolean
Validates an MSISDN.
Instance Method Details
#msisdn(options_hash = {}) ⇒ String?
Validates and converts an MSISDN in the string to the required format.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mobme_support/core_ext/string/msisdn.rb', line 27 def msisdn( = {}) = { :country => 'IN', :format => 'local' } = .symbolize_keys.reverse_merge() @@msdn_format_data ||= YAML.load_file(File.dirname(__FILE__) + "/msisdn_formats.yml") msisdn_format = @@msdn_format_data[[:country]] msisdn = self.strip if msisdn.match(msisdn_format['regexp']) local_segment = msisdn[-(msisdn_format['local_digits'])..-1] case [:format] when 'local' local_segment when 'country' "#{msisdn_format['country_code']}#{local_segment}" when 'plus_country' "+#{msisdn_format['country_code']}#{local_segment}" when "international" "#{msisdn_format['international_prefix']}#{msisdn_format['country_code']}#{local_segment}" end else nil end end |
#msisdn?(options_hash = {}) ⇒ Boolean
Validates an MSISDN.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mobme_support/core_ext/string/msisdn.rb', line 67 def msisdn?( = {}) = { :country => 'IN', :format => 'local' } = .symbolize_keys.reverse_merge() @@msdn_format_data ||= YAML.load_file(File.dirname(__FILE__) + "/msisdn_formats.yml") msisdn_format = @@msdn_format_data[[:country]] return false unless self =~ msisdn_format['regexp'] true end |