MasterData
masterdata mostly used for validations of countrycodes, country, states, countrydailcode, contactnumbers, pincodes and emailaddress which can be helpful for data preprocessing. Along with this something special is that gaining the information from country/countrycodes/countrydailcodes.Lets look the more about the functions of how to master the data from a csv table.
Installation
Add this line to your application's Gemfile:
gem 'masterdata'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install masterdata
There are few functions which we can operate on table columns or symbolized hash data .the following are list of functions..
- read_csv
- val_countrystate
- val_dailcode
- val_pincode
- val_contactnumber
- val_emailaddress
- infogain_country
- infogain_countrycode
- infogain_countrydialcode
- update_columns
- validate_abbrevate_countrycodes
Note:
- Masterdata can deal with csv data or Symbolized hash data
- "N" for null value
- "I" for invalid
Read csv file :
Read the csv file just by providing the link to the function and get the table in the form of symbol hash data. if columns have any null values it will be written as "N"(null value)
csv file : foo.csv
------------------------------------------=-
! Country ! DailCode ! CountryCode !
!------------==!-------------!-------------!
! India ! +91 ! IN !
!--------------!-------------!-------------!
! United States! +1 | US !
--------------------------------------------
# provide link of csv file
Masterdata::read_csv("C:\\user\\foo.csv")
# symbolized hash data
{:country=>[India,United States],:dialcode=>["91","1"],:countrycode=>["IN","US"]}
# if you observe above columns are converted to lowercase by default in ruby for symbolized hash
validate country and state
Assume you have two columns of country and state for validation one more argument is passed along which is country code ["IN","US"]. pass three arguments
- csv symbolized hash data
- Array of country and state
- countrycode column
ruby #country = ["India","United states"] #states = ["Delhi","Tokyo"] #countrycode = ["IN","US"] Masterdata::val_countrystate(csv_sym_hash_data,["country","states"],"countrycode") # => [["India","United states"],["Delhi","I"]] # "I" for invalid
### validate country dailcode Validate countries dial codes of a csv columnruby # dialcode=["91","1","zz","0"] Masterdata::val_dialcode(csv_sym_hash_data,"dialcode") # => ["+91","+1","I","I"] # "I" for invalid
### validate country pincode To validate the pincode it require columns pincode and countrycode because to validate the pincode its depends on countryruby # countrycode = ["IN","ZZ"] # dialcode = ["505325","505321"] Masterdata::val_dialcode(pincode,countrycode) # ["505325","I"] # "I" for invalid
validate phone numbers
validate contacts based on countries
# contactnumber = ["+91779398005","+16505130514"]
# countrycode = ["IN","US"]
Masterdata::val_contactnumber(contactnumber,countrycode)
# => ["I","+16505130514"]
# "I" for invalid
validate email address
emailaddress = ["[email protected]","[email protected]","steve@mail"]
Masterdata::val_emailaddress(emailaddress)
# => ["[email protected]","[email protected]","I"]
# "I" for invalid
Gain the information
Gain the information just by proving any columns like countrycode or country or countrydialcode. In the (infogain_countrydialcode) function just provide dialcode without "+" symbol
# give countrycode ["IN"] and get country & dialcode ["India", "+91"]
Masterdata::infogain_countrycode(csv_sym_hash_data,"countrycode")
# give ["India"] and get countrycode & dialcode ["IN", "+91"]
Masterdata::infogain_country(csv_sym_hash_data,"country")
# give ["91"] and get country and countrycode ["India", "IN"]
Masterdata::infogain_countrydialcode(csv_sym_hash_data,"countrydialcode")
Validate countrycodes and abrrevate
validate countrycode column which return proper countrycodes and get bonus with abbrevated countrynames
# countrycode = ["IN","US","z"]
Masterdata::validate_abbrevate_countrycodes(csv_sym_hash_data,"countrycode")
# => [["IN","US","I"] , ["India","United States","N"]]
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/sairam6267/masterdata. This project is intended to be a safe, welcoming space for collaboration.
License
The gem is available as open source under the terms of the MIT License.