Module: Masterdata
- Defined in:
- lib/masterdata.rb,
lib/masterdata/version.rb,
lib/masterdata/dialcode.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.5.0"
- @@country_codes =
I18nData.countries.keys().map(&:downcase)
- @@country_names =
I18nData.countries.values().map(&:downcase)
- @@dialcode =
Masterdata::dialcode_country
Class Method Summary collapse
- .dialcode_country ⇒ Object
- .infogain_country(csv_data, column) ⇒ Object
- .infogain_countrycode(csv_data, column) ⇒ Object
- .infogain_countrydialcode(csv_data, column) ⇒ Object
- .read_csv(path) ⇒ Object
- .update_columns(csv_data, headers, header_values) ⇒ Object
- .val_contactnumber(contact_col, countrycode_col) ⇒ Object
- .val_countrystate(csv_data, col, countrycol) ⇒ Object
- .val_dialcode(csv_data, dialcol) ⇒ Object
- .val_emailaddress(emailcol) ⇒ Object
- .val_pincode(pincode_col, countrycode_col) ⇒ Object
- .validate_abbrevate_countrycodes(csv_data, countrycodecol) ⇒ Object
Class Method Details
.dialcode_country ⇒ Object
4 5 6 |
# File 'lib/masterdata/dialcode.rb', line 4 def dialcode_country dialcode_country={"+93"=>"Afghanistan", "+355"=>"Albania", "+213"=>"Algeria", "+1"=>"United States", "+376"=>"Andorra", "+244"=>"Angola", "+54"=>"Argentina", "+374"=>"Armenia", "+297"=>"Aruba", "+61"=>"Australia", "+672"=>"Australian External Territories", "+43"=>"Austria", "+994"=>"Azerbaijan", "+973"=>"Bahrain", "+880"=>"Bangladesh", "+375"=>"Belarus", "+32"=>"Belgium", "+501"=>"Belize", "+229"=>"Benin", "+975"=>"Bhutan", "+591"=>"Bolivia ", "+599"=>"Curaçao", "+387"=>"Bosnia and Herzegovina", "+267"=>"Botswana", "+55"=>"Brazil", "+673"=>"Brunei Darussalam", "+359"=>"Bulgaria", "+226"=>"Burkina Faso", "+257"=>"Burundi", "+855"=>"Cambodia", "+237"=>"Cameroon", "+238"=>"Cape Verde", "+236"=>"Central African Republic", "+235"=>"Chad", "+56"=>"Chile", "+86"=>"China", "+57"=>"Colombia", "+269"=>"Comoros", "+242"=>"Congo", "+682"=>"Cook Islands", "+506"=>"Costa Rica", "+225"=>"Côte d'Ivoire", "+385"=>"Croatia", "+53"=>"Cuba", "+357"=>"Cyprus", "+420"=>"Czech Republic", "+850"=>"North Korea", "+243"=>"Democratic Republic of the Congo", "+45"=>"Denmark", "+246"=>"Diego Garcia", "+253"=>"Djibouti", "+593"=>"Ecuador", "+20"=>"Egypt", "+503"=>"El Salvador", "+240"=>"Equatorial Guinea", "+291"=>"Eritrea", "+372"=>"Estonia", "+251"=>"Ethiopia", "+500"=>"Falkland Islands ", "+298"=>"Faroe Islands", "+679"=>"Fiji", "+358"=>"Finland", "+33"=>"France", "+262"=>"Mayotte", "+594"=>"French Guiana", "+689"=>"French Polynesia", "+241"=>"Gabon", "+220"=>"Gambia", "+995"=>"Georgia", "+49"=>"Germany", "+233"=>"Ghana", "+350"=>"Gibraltar", "+881"=>"Global Mobile Satellite System , shared", "+30"=>"Greece", "+299"=>"Greenland", "+388"=>"Group of countries, shared code", "+590"=>"Guadeloupe", "+502"=>"Guatemala", "+224"=>"Guinea", "+245"=>"Guinea-Bissau", "+592"=>"Guyana", "+509"=>"Haiti", "+504"=>"Honduras", "+852"=>"Hong Kong", "+36"=>"Hungary", "+354"=>"Iceland", "+91"=>"India", "+62"=>"Indonesia", "+870"=>"Inmarsat SNAC", "+800"=>"International Freephone Service", "+882"=>"International Networks, shared code", "+883"=>"International Networks, shared code", "+979"=>"International Premium Rate Service ", "+808"=>"International Shared Cost Service ", "+98"=>"Iran ", "+964"=>"Iraq", "+353"=>"Ireland", "+972"=>"Israel", "+39"=>"Vatican", "+81"=>"Japan", "+962"=>"Jordan", "+7"=>"Russian Federation", "+254"=>"Kenya", "+686"=>"Kiribati", "+82"=>"Korea ", "+965"=>"Kuwait", "+996"=>"Kyrgyzstan", "+856"=>"Lao P.D.R.", "+371"=>"Latvia", "+961"=>"Lebanon", "+266"=>"Lesotho", "+231"=>"Liberia", "+218"=>"Libya", "+423"=>"Liechtenstein", "+370"=>"Lithuania", "+352"=>"Luxembourg", "+853"=>"Macao", "+261"=>"Madagascar", "+265"=>"Malawi", "+60"=>"Malaysia", "+960"=>"Maldives", "+223"=>"Mali", "+356"=>"Malta", "+692"=>"Marshall Islands", "+596"=>"Martinique", "+222"=>"Mauritania", "+230"=>"Mauritius", "+52"=>"Mexico", "+691"=>"Micronesia", "+373"=>"Moldova ", "+377"=>"Monaco", "+976"=>"Mongolia", "+382"=>"Montenegro", "+212"=>"Morocco", "+258"=>"Mozambique", "+95"=>"Myanmar", "+264"=>"Namibia", "+674"=>"Nauru", "+977"=>"Nepal", "+31"=>"Netherlands", "+687"=>"New Caledonia", "+64"=>"New Zealand", "+505"=>"Nicaragua", "+227"=>"Niger", "+234"=>"Nigeria", "+683"=>"Niue", "+47"=>"Norway", "+968"=>"Oman", "+92"=>"Pakistan", "+680"=>"Palau", "+507"=>"Panama", "+675"=>"Papua New Guinea", "+595"=>"Paraguay", "+51"=>"Peru", "+63"=>"Philippines", "+48"=>"Poland", "+351"=>"Portugal", "+974"=>"Qatar", "+40"=>"Romania", "+250"=>"Rwanda", "+247"=>"Saint Helena, Ascension and Tristan da Cunha", "+290"=>"Saint Helena, Ascension and Tristan da Cunha", "+508"=>"Saint Pierre and Miquelon", "+685"=>"Samoa", "+378"=>"San Marino", "+239"=>"Sao Tome and Principe", "+966"=>"Saudi Arabia", "+221"=>"Senegal", "+381"=>"Serbia", "+248"=>"Seychelles", "+232"=>"Sierra Leone", "+65"=>"Singapore", "+421"=>"Slovakia", "+386"=>"Slovenia", "+677"=>"Solomon Islands", "+252"=>"Somalia", "+27"=>"South Africa", "+211"=>"South Sudan", "+34"=>"Spain", "+94"=>"Sri Lanka", "+249"=>"Sudan", "+597"=>"Suriname", "+268"=>"Swaziland", "+46"=>"Sweden", "+41"=>"Switzerland", "+963"=>"Syrian Arab Republic", "+886"=>"Taiwan, China", "+992"=>"Tajikistan", "+255"=>"Tanzania", "+888"=>"Telecommunications for Disaster Relief ", "+66"=>"Thailand", "+389"=>"The Former Yugoslav Republic of Macedonia", "+670"=>"Timor-Leste", "+228"=>"Togo", "+690"=>"Tokelau", "+676"=>"Tonga", "+991"=>"Trial of a proposed new international service", "+216"=>"Tunisia", "+90"=>"Turkey", "+993"=>"Turkmenistan", "+688"=>"Tuvalu", "+256"=>"Uganda", "+380"=>"Ukraine", "+971"=>"United Arab Emirates", "+44"=>"United Kingdom", "+878"=>"Universal Personal Telecommunication ", "+598"=>"Uruguay", "+998"=>"Uzbekistan", "+678"=>"Vanuatu", "+379"=>"Vatican", "+58"=>"Venezuela ", "+84"=>"Viet Nam", "+681"=>"Wallis and Futuna", "+967"=>"Yemen", "+260"=>"Zambia", "+263"=>"Zimbabwe", "+970"=>"Reserved"} end |
.infogain_country(csv_data, column) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/masterdata.rb', line 101 def infogain_country(csv_data,column) infogainc = [] csv_data[column.to_sym].each do |codes| # p codes if (codes =="I" || codes == "N") #country infogainc << ["NO INFO","NO INFO"] else infogainc << [I18nData.country_code(codes),IsoCountryCodes.find(I18nData.country_code(codes)).calling] end end return infogainc end |
.infogain_countrycode(csv_data, column) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/masterdata.rb', line 88 def infogain_countrycode(csv_data,column) infogaincc = [] csv_data[column.to_sym].each do |codes| # p codes if (codes =="I" || codes == "N") #countrycodes infogaincc << ["NO INFO",codes,"NO INFO"] else infogaincc << [NormalizeCountry(IsoCountryCodes.find(codes).name , :to => :short) , IsoCountryCodes.find(codes).calling] end end return infogaincc end |
.infogain_countrydialcode(csv_data, column) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/masterdata.rb', line 114 def infogain_countrydialcode(csv_data,column) infogaincdc = [] csv_data[column.to_sym].each do |codes| # p codes if (codes =="I" || codes == "N") #countrydialcodes infogaincdc << ["NO INFO","NO INFO"] else infogaincdc << [@@dialcode[codes],I18nData.country_code(@@dialcode[codes])] end end return infogaincdc end |
.read_csv(path) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/masterdata.rb', line 20 def read_csv(path) data = {} df = CSV.table(path) df.headers.each do |column| data.merge!(column=>df[column].map{|values| values.class==NilClass ? "N" : values}.map(&:to_s)) end return data end |
.update_columns(csv_data, headers, header_values) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/masterdata.rb', line 127 def update_columns(csv_data,headers,header_values) headers = headers.map{|x| x.to_sym} headers.each_with_index do |data,index| csv_data[headers[index]].replace(header_values[index]) end return csv_data end |
.val_contactnumber(contact_col, countrycode_col) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/masterdata.rb', line 151 def val_contactnumber(contact_col,countrycode_col) valcontactnumber = [] contact_col.each_with_index do |data,index| if Phonelib.valid_for_country?(data,countrycode_col[index]) valcontactnumber << data else valcontactnumber << "I" end end return valcontactnumber end |
.val_countrystate(csv_data, col, countrycol) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/masterdata.rb', line 49 def val_countrystate(csv_data,col,countrycol) col = col.map{|e| e.to_sym} state_names = [] csv_data[countrycol.to_sym].map{|code| if code.size==2 then state_names << CS.states(code.downcase.to_sym).values() end} #states names getting country_state_names= (@@country_names << state_names.compact().flatten.map(&:downcase)).flatten #collecting all country and state names # val_country_state_names = [:state,:country] col.each do |ele| csv_data[ele].each_with_index do |data,index| if data !="N" if country_state_names.include?(data.downcase) csv_data[ele][index] = data #validating states and country names else csv_data[ele][index] = "I" end elsif data == "N" csv_data[ele][index] = "N" else csv_data[ele][index] end end end return col.map{|e| csv_data[e]} end |
.val_dialcode(csv_data, dialcol) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/masterdata.rb', line 73 def val_dialcode(csv_data,dialcol) country_dail_codes = @@country_codes.map(&:upcase).map{|codes| IsoCountryCodes.find(codes).calling[1..-1]} # collecting all country dial codes from countries val_country_dail_codes = [] csv_data[dialcol.to_sym].each do |i| if country_dail_codes.include?(i) val_country_dail_codes << "+#{i}" # validating column dial codes elsif i == "N" val_country_dail_codes << "N" else val_country_dail_codes << "I" end end return val_country_dail_codes end |
.val_emailaddress(emailcol) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/masterdata.rb', line 163 def val_emailaddress(emailcol) valemailcol = [] emailcol.each do |val| # p val if val != "N" if EmailAddress.valid?(val) valemailcol << val else valemailcol << "I" end else valemailcol << "N" end end return valemailcol end |
.val_pincode(pincode_col, countrycode_col) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/masterdata.rb', line 135 def val_pincode(pincode_col,countrycode_col) pincodes = [] pincode_col.each_with_index do |data,index| if data != "N" if ValidatesZipcode.valid?(data,countrycode_col[index]) pincodes << data else pincodes << "I" end else pincodes << "N" end end return pincodes end |
.validate_abbrevate_countrycodes(csv_data, countrycodecol) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/masterdata.rb', line 31 def validate_abbrevate_countrycodes(csv_data,countrycodecol) alpha_country_codes = [] abbre_country_codes = [] csv_data[countrycodecol.to_sym].map(&:downcase).each do |alpha2| if @@country_codes.include?(alpha2[0,2]) alpha_country_codes << alpha2[0,2] # validating country codes abbre_country_codes << NormalizeCountry(alpha2[0,2].upcase, :to => :short) #abbrevating CountryCodes after validation elsif alpha2=="N" alpha_country_codes << alpha2 abbre_country_codes << alpha2 else alpha_country_codes << "I" # invalid abbre_country_codes << "N" # null value end end return alpha_country_codes , abbre_country_codes end |