Module: UKPhoneNumbers

Defined in:
lib/uk_phone_numbers.rb,
lib/uk_phone_numbers/version.rb

Constant Summary

PATTERNS =
<<-PATTERNS
  (01###) #####[#]
  (011#) ### ####
  (01#1) ### ####
  (013873) #####
  (015242) #####
  (015394) #####
  (015395) #####
  (015396) #####
  (016973) #####
  (016974) #####
  (016977) ####[#]
  (017683) #####
  (017684) #####
  (017687) #####
  (019467) #####
  (02#) #### ####
  03## ### ####
  05### ######
  0500 ######
  07### ######
  08## ### ###[#]
  09## ### ####
PATTERNS
REGEXPS =
[]
VERSION =
'0.1.0'

Class Method Summary (collapse)

Class Method Details

+ (Object) format(number, opts = {})



49
50
51
52
# File 'lib/uk_phone_numbers.rb', line 49

def self.format(number, opts = {})
  match = REGEXPS.map { |r| r.match(number) }.reject(&:nil?).first
  match ? match[1..-1].join(opts[:separator] || ' ') : false
end

+ (Object) pattern_to_regexp(pattern)



28
29
30
31
32
33
34
35
# File 'lib/uk_phone_numbers.rb', line 28

def self.pattern_to_regexp(pattern)
  regexp = pattern.dup
  regexp.gsub!(/[()]/, '')
  regexp = regexp.split.map { |p| "(#{p})" }.join
  regexp.gsub!(/\[([^\]]*)\]/, '(?:\1)?')
  regexp.gsub!(/#/, '\d')
  Regexp.new("^#{regexp}$")
end

+ (Boolean) valid?(number)



45
46
47
# File 'lib/uk_phone_numbers.rb', line 45

def self.valid?(number)
  REGEXPS.select { |r| r.match(number) }.any?
end