Class: Knykode::Mobile

Inherits:
Object
  • Object
show all
Defined in:
lib/knykode/mobile.rb

Instance Method Summary collapse

Instance Method Details

#airtel_prefixesObject



37
38
39
# File 'lib/knykode/mobile.rb', line 37

def airtel_prefixes
  ['0730','0731','0732','0733','0734','0735','0746','0737','0738','0739']
end

#carriersObject



4
5
6
# File 'lib/knykode/mobile.rb', line 4

def carriers
  ['Safaricom','Airtel','Yu','Orange','Telkom']
end

#detect_carrier(number) ⇒ Object

given a phone number determine the carrier



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/knykode/mobile.rb', line 9

def detect_carrier(number)
  prefix = number.to_s[0,4] unless number.start_with?('+')

  case
  when safaricom_prefixes.include?(prefix)
    carrier = 'Safaricom'

  when yu_prefixes.include?(prefix)
    carrier = 'Yu'

  when airtel_prefixes.include?(prefix)
    carrier = 'Airtel'

  when orange_prefixes.include?(prefix)
    carrier = 'Orange'
  else
    carrier = 'unrecognized format'

  end
  carrier
end

#orange_prefixesObject



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

def orange_prefixes
  ['0770','0772','0773','0774','0775']
end

#safaricom_prefixesObject



31
32
33
34
35
# File 'lib/knykode/mobile.rb', line 31

def safaricom_prefixes
  ['0700','0701','0702','0703','0704','0705','0706','0707','0708','0709','0710',
   '0711','0712','0713','0714','0715','0716','0717','0718','0719','0720','0721',
   '0722','0723','0724','0725','0726','0728','0729']	
end

#yu_prefixesObject



41
42
43
# File 'lib/knykode/mobile.rb', line 41

def yu_prefixes
  ['0750','0751','0752','0753','0754','0755']
end