Class: PhoneClassifier
- Inherits:
-
Object
- Object
- PhoneClassifier
- Defined in:
- lib/phone_classifier.rb
Instance Method Summary collapse
- #forbidden? ⇒ Boolean
-
#initialize(number) ⇒ PhoneClassifier
constructor
authorative info: www.itu.int/oth/T0202.aspx?parent=T0202 Numbering schemes for mobile numbers.
- #is_number_of_type(numbers) ⇒ Object
- #kind ⇒ Object
- #mobile? ⇒ Boolean
Constructor Details
#initialize(number) ⇒ PhoneClassifier
authorative info: www.itu.int/oth/T0202.aspx?parent=T0202 Numbering schemes for mobile numbers
13 14 15 |
# File 'lib/phone_classifier.rb', line 13 def initialize number @number = number end |
Instance Method Details
#forbidden? ⇒ Boolean
33 34 35 |
# File 'lib/phone_classifier.rb', line 33 def forbidden? return is_number_of_type Forbidden.data end |
#is_number_of_type(numbers) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/phone_classifier.rb', line 37 def is_number_of_type numbers parts = Phony.split Phony.normalize(@number) ndcs = numbers[parts.shift] prefix = parts.shift return false unless ndcs # if we don't know the country, we can make no assumptions # countries without NDCs (Denmark) have this parts structure ["45", false, "40", "53", "25", "77"] until parts.size == 0 || prefix.is_a?(String) prefix = parts.shift end ndcs.each { |n| return true if prefix.match(/^#{n}$/) } unless ndcs.nil? false end |
#kind ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/phone_classifier.rb', line 17 def kind case when self.mobile? then :mobile when self.forbidden? then :forbidden else :landline end end |