Class: WillItDial::US
- Inherits:
-
Object
- Object
- WillItDial::US
- Defined in:
- lib/will_it_dial.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
Class Method Summary collapse
Instance Method Summary collapse
- #banned? ⇒ Boolean
- #check ⇒ Object
- #duplicates?(max_dupes = 7) ⇒ Boolean
- #fake_area_code? ⇒ Boolean
- #fake_exchange_code? ⇒ Boolean
-
#initialize(phonenumber) ⇒ US
constructor
A new instance of US.
- #invalid? ⇒ Boolean
- #suspicious? ⇒ Boolean
- #too_short?(len = 10) ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(phonenumber) ⇒ US
Returns a new instance of US.
11 12 13 |
# File 'lib/will_it_dial.rb', line 11 def initialize(phonenumber) self.number = phonenumber end |
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
4 5 6 |
# File 'lib/will_it_dial.rb', line 4 def number @number end |
Class Method Details
.check(num) ⇒ Object
6 7 8 9 |
# File 'lib/will_it_dial.rb', line 6 def self.check(num) inst = self.new(num) inst.check end |
Instance Method Details
#banned? ⇒ Boolean
27 28 29 |
# File 'lib/will_it_dial.rb', line 27 def banned? banned_numbers.include?(number[3,8]) end |
#check ⇒ Object
15 16 17 |
# File 'lib/will_it_dial.rb', line 15 def check !(invalid? || suspicious? || banned?) end |
#duplicates?(max_dupes = 7) ⇒ Boolean
46 47 48 49 50 51 52 53 54 |
# File 'lib/will_it_dial.rb', line 46 def duplicates?(max_dupes = 7) num_arr = number.split('') num_arr[0,num_arr.length - max_dupes + 1].each_with_index do |n,i| if same_numbers?(num_arr[i,max_dupes]) return true end end false end |
#fake_area_code? ⇒ Boolean
61 62 63 |
# File 'lib/will_it_dial.rb', line 61 def fake_area_code? !all_area_codes.include?(number[0,3]) end |
#fake_exchange_code? ⇒ Boolean
56 57 58 59 |
# File 'lib/will_it_dial.rb', line 56 def fake_exchange_code? # Per wikipedia, no x11 or 0xx 1xx exchange codes (number[3,1].to_i == 1) || (number[3,1].to_i == 0) || (number[4,2].to_i == 11) end |
#invalid? ⇒ Boolean
19 20 21 |
# File 'lib/will_it_dial.rb', line 19 def invalid? too_short? || fake_area_code? || fake_exchange_code? end |
#suspicious? ⇒ Boolean
23 24 25 |
# File 'lib/will_it_dial.rb', line 23 def suspicious? (!!number.match(/1234/) || same_numbers?(number[-4,4]) || (unique_numbers(number) <= 2) || duplicates?) end |
#too_short?(len = 10) ⇒ Boolean
42 43 44 |
# File 'lib/will_it_dial.rb', line 42 def too_short?(len = 10) number.length < len end |
#valid? ⇒ Boolean
31 32 33 |
# File 'lib/will_it_dial.rb', line 31 def valid? !invalid? end |