# CompanyNumber [](https://github.com/victorauthiat/company_number/actions/workflows/build.yml) CompanyNumber is a gem allowing you to validate company number based on a country code ## Installation Add this line to your application's Gemfile: ```ruby gem 'company_number' ``` And then execute: $ bundle install Or install it yourself as: $ gem install company_number ## Usage You can obtain a `CompanyNumber::Number` object calling `parse` method: ```ruby company_number = CompanyNumber.parse('123456789', :fr) # => #<CompanyNumber::Number:0x00007fd945013d50 @company_number="123456789", @countries=[:bg, :fr, :gr, :lt, :no, :pt, :si, :ch, :gb], @country_code=:fr, @regexp=/^(\d{9}|\d{14})$/> ``` Then you can run validation methods ```ruby company_number.valid? # => true company_number.valid_country? # => true company_number.valid_for_country?(:at) # => false ``` You can also fetch matched countries ```ruby company_number.countries # => [:bg, :fr, :gr, :lt, :no, :pt, :si, :ch, :gb] ``` There is a `to_s` method, which returns the company number with the country code. ```ruby company_number.to_s # => "123456789 fr" ``` There is a `to_h` method, which returns all attr_reader ```ruby company_number.to_h # => {:company_number=>"123456789", :country_code=>:fr, :countries=>[:bg, :fr, :gr, :lt, :no, :pt, :si, :ch, :gb], :regexp=>/^(\d{9}|\d{14})$/} ``` You can compare 2 instances of `CompanyNumber::Number` with `==` method ```ruby CompanyNumber.parse('123') == CompanyNumber.parse('123') # => true ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. 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](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/victorauthiat/company_number. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/victorauthiat/company_number/blob/master/CODE_OF_CONDUCT.md). ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). ## Code of Conduct Everyone interacting in the CompanyNumber project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/victorauthiat/company_number/blob/master/CODE_OF_CONDUCT.md).