Module: NoPhone
- Defined in:
- lib/no_phone.rb,
lib/no_phone/version.rb
Constant Summary collapse
- VERSION =
"0.0.7"
Instance Method Summary collapse
-
#international?(number) ⇒ Boolean
Norway-centric.
- #msisdnize(number) ⇒ Object
- #normalize(number) ⇒ Object
- #number_valid?(number) ⇒ Boolean
- #unmsisdnize(number) ⇒ Object
Instance Method Details
#international?(number) ⇒ Boolean
Norway-centric. True if not a norwegian number.
38 39 40 |
# File 'lib/no_phone.rb', line 38 def international?(number) !!(normalize(number) =~ /^\+/) end |
#msisdnize(number) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/no_phone.rb', line 14 def msisdnize(number) return nil if missing?(number) number = normalize(number) number = "47#{number}" unless number =~ /^\+/ number.gsub!(/^\+/, '') number end |
#normalize(number) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/no_phone.rb', line 3 def normalize(number) number ||= "" number = number.gsub(/[.\- \t\r\n\(\)]/, '') number.gsub!(/^(\+)(.*)/) { |m| $1 + $2.gsub(/\+/, '') } number.gsub!(/^00/, '+') number.gsub!(/^\+47/, '') number.gsub!(/^\+*0+/, '+') number.gsub!(/^47/, '') if number.size > 8 number end |
#number_valid?(number) ⇒ Boolean
27 28 29 30 31 32 33 34 35 |
# File 'lib/no_phone.rb', line 27 def number_valid?(number) return false if number.nil? return false if number == "" case number.strip when /\A\+?[0-9[:space:]]+\z/ return true end false end |
#unmsisdnize(number) ⇒ Object
23 24 25 |
# File 'lib/no_phone.rb', line 23 def unmsisdnize(number) normalize("+#{number}") if number end |