Last active
June 23, 2016 11:35
-
-
Save mtelis/490501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash; alias :+ :merge; end; Home,Mobile,Work,Gizmo = 1,2,3,7 | |
# **** My classes. DO NOT EDIT from here ********************************* # | |
class VSP | |
@vsptab = {} | |
def self.tab; @vsptab; end | |
attr_reader :fmt, :name, :repeat, :tmo | |
def initialize *args | |
attrib = args.pop | |
args << attrib and attrib = {} unless attrib.class == Hash | |
@pfx, @fmt, @name = args | |
attrib.empty? || %w{pfx name tmo fmt repeat rand}.each do |attr| | |
ivar = "@#{attr}"; val = attrib.delete(attr.to_sym) | |
instance_variable_set(ivar,val) if val && !instance_variable_get(ivar) | |
end | |
@repeat ||= 1; @fmt ||= '+${EXTEN}' if is_gv? | |
unless @pfx.to_s.empty? | |
raise "Duplicated dial prefix '#{@pfx}'" if VSP.tab.has_key?(@pfx) | |
VSP.tab[@pfx] = self | |
end | |
@attrib = attrib if is_gv? | |
end | |
def is_gv?; self.class == GV; end | |
end | |
class GV < VSP | |
attr_reader :rand | |
def getparams num, i=0 | |
acnt = @attrib[:account] || Array[@attrib] | |
a = {:num => num, :tmo => @tmo || 10, :match => '.*'} # init with default values | |
a.update(acnt[i % acnt.length]) # add other params | |
a[:cb].gsub!(/\D/,'') # Delete all but digits | |
a[:cb] = '+' + a[:cb] # Prepend with "+" | |
a[:type] ||= (a[:cb] =~ /^1?747/) ? Gizmo : Home # if no type, define it depending on area code | |
a.values_at(:usr, :pwd, :cb, :num, :match, :type, :tmo) | |
end | |
end | |
def Provider(*args) | |
a = args.last; a.class == Hash && (a[:usr] || a[:account]) ? GV.new(*args) : VSP.new(*args) | |
end | |
# **** .......................... to here ******************************** # | |
# ************************* f o r m a t N u m **************************** | |
def formatNum(num,exact=false) | |
case num | |
# Closed Numbering Plan | |
when /^(39)(0[26]|0\d[0159]|0\d{3}|3\d\d)(\d*)(\d{4})$/, # Italy: Milan, Rome, 0x0, 0x1, 0x5, 0x9, 4-digit | |
/^(41|48)(\d{2})(\d{3})(\d{4})$/, # Swiss, Poland | |
/^(34)(9[1-9]|[5-9]\d\d)(\d{3})(\d{3,4})$/, # Spain | |
/^(32)(4[789]\d|[89]0\d|[2-4]|[15-8]\d)(\d{3})(\d{3,4})$/, # Belgium | |
/^(86)(1[2-9]\d)(\d{3,4})(\d{4})$/, # China mobile | |
/^(886)(37|49|89|\d)(\d*)(\d{4})$/, # Taiwan | |
/^(972)(\d{1,2})(\d{3})(\d{4})$/, # Israel | |
/^(31)(6|800|8\d|9\d\d)(\d*)(\d{4})$/ # Netherlands non-geo | |
sep = $3[2] ? '-' : '' # separator if $3 group has 3 or more digits | |
"+#$1 #$2 #$3#{sep}#$4" | |
# Open Numbering Plan | |
when /^([17]|90)(\d{3})(\d{3})(\d{4})$/, # USA, Russia, Turkey | |
/^(61)(\d)(\d{4})(\d{4})/, # Australia | |
/^(49)(1[5-7]\d|30|40|69|89|\d\d1|\d{4})(\d*)(\d{4})$/, # Germany: (mobile|2dig|3dig|4dig) area | |
/^(380|375|998)(\d{2})(\d{3})(\d{4})$/, # Ukraine, Belarus, Uzbekistan | |
/^(370)(469|528|37|45|46|57|5|\d{3})(\d*)(\d{4})$/, # Lithuania | |
/^(36)(1|\d\d)(\d{3})(\d{3,4})$/, # Hungary | |
/^(86)(10|2\d|\d{3})(\d{3,4})(\d{4})$/, # China: Beijing, 2x, others 3-dig area code | |
/^(91)(800|11|20|33|40|44|[789]\d|\d{3})(\d*)(\d{4})$/, # India | |
/^(63)(2|[3-8]\d|9\d\d)(\d{3})(\d{4})$/, # Philippines (Manila, [3-8]x, 9xx - mobile) | |
/^(81)(3|6|[2-9]0|\d\d0|\d\d)(\d*)(\d{4})$/, # Japan | |
/^(55)(\d\d)(\d{4})(\d{4})$/, # Brazil | |
/^(31)(7\d|[1-5][035]|2[46]|3[68]|46|58|\d{3})(\d*)(\d{4})$/ # Netherlands geo | |
sep = $3[2] ? '-' : '' # separator if $3 group has 3 or more digits | |
"+#$1 (#$2) #$3#{sep}#$4" | |
when /^(52)(1)?(33|55|81|\d{3})(\d*)(\d{4})$/ # Mexico | |
"+#$1#{$2.nil? ? '' : ' ' + $2} #$3 #$4-#$5" | |
when /^(33)(\d)(\d{2})(\d{2})(\d{2})(\d{2})$/ # France | |
"+#$1 #$2 #$3 #$4 #$5 #$6" | |
when /^(44)(11\d|1\d1|2\d|[389]\d\d)(\d{3,4})(\d{4})$/, # UK 2- and 3-digit area codes: 11x, 1x1, 2x, 3xx, 8xx, 9xx | |
/^(44)(\d{4})(\d{3})(\d{3,4})$/ # UK 4-digit area codes | |
"+#$1 (#$2) #$3 #$4" | |
when /^(420)(\d{3})(\d{3})(\d{3})$/ # Czech Republic | |
"+#$1 #$2 #$3 #$4" | |
when /^(37[12])(\d{3,4})(\d{4})$/ # Latvia, Estonia | |
"+#$1 #$2-#$3" | |
when /^(373)([67]\d{2})(\d{2})(\d{3})$/ # Moldova mobile | |
"+#$1 #$2-#$3-#$4" | |
when /^(373)(22|\d{3})(\d{1,2})(\d{2})(\d{2})$/ # Moldova landline | |
"+#$1 (#$2) #$3-#$4-#$5" | |
when /^(1|2[07]|3[0-469]|4[^2]|5[1-8]|6[0-6]|7|8[1246]|9[0-58]|\d{3})/ # all country codes | |
exact ? num : "+#$1 #$'" # the pattern used only if exact == false | |
else num # No match - skip formatting | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment