Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding MacAddress and IBAN support #11

Merged
merged 4 commits into from Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,13 +1,13 @@
PATH
remote: .
specs:
ruby_regex (0.1.0)
ruby_regex (0.1.1)
rake

GEM
remote: https://rubygems.org/
specs:
rake (10.1.0)
rake (10.1.1)

PLATFORMS
ruby
Expand Down
8 changes: 8 additions & 0 deletions lib/ruby_regex.rb
Expand Up @@ -63,4 +63,12 @@ module RubyRegex

# SpanishBankAccountNumber
SpanishBankAccountNumber = /\A\d{4}[ -]?\d{4}[ -]?\d{2}[ -]?\d{10}\z/

# IBAN
# Source: http://snipplr.com/view/15322/iban-regex-all-ibans/
# You have to remove spaces or any separator character from the original field before use this regex
IBAN = /[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}/

# MacAddress
MacAddress = /\A([0-9A-F]{2}[:-]){5}([0-9A-F]{2})\z/i
end
21 changes: 21 additions & 0 deletions test/fixtures/ibans.yml
@@ -0,0 +1,21 @@
valid:
- "AT611904300234573201"
- "AZ21NABZ00000000137010001944"
- "BH67BMAG00001299123456"
- "BE62510007547061"
- "BA39129007940108494"
- "BG80BNBG9661102345678"
- "HR121001005186300160"
- "CY1700200128000001200527600"
- "CZ650800000019200145399"
- "DK500040044011643"
- "EE38220022102015685"
- "FR142004101005000013M02606"


invalid:
- ""
- "11"
- "111122223344444444445"
- "1111222233 4444444444"
- "1111222233-4444444444"
8 changes: 8 additions & 0 deletions test/fixtures/mac_addresses.yml
@@ -0,0 +1,8 @@
valid:
- "aa:aa:aa:aa:aa:aa"
- "FF:FF:FF:FF:FF:FF"

invalid:
- "Not valid"
- "FF,FF,FF,FF,FF,FF"
- "FF:FF:FF:FF:FF"
18 changes: 18 additions & 0 deletions test/ruby_regex_test.rb
Expand Up @@ -156,6 +156,24 @@ def test_invalid_spanish_bank_account_numbers
check_invalid_regex RubyRegex::SpanishBankAccountNumber, load_fixture('spanish_bank_account_numbers')['invalid']
end

# IBAN
def test_valid_iban
check_valid_regex RubyRegex::IBAN, load_fixture('ibans')['valid']
end

def test_invalid_iban
check_invalid_regex RubyRegex::IBAN, load_fixture('ibans')['invalid']
end

# MacAddress
def test_valid_mac_addresses
check_valid_regex RubyRegex::MacAddress, load_fixture('mac_addresses')['valid']
end

def test_invalid_mac_addresses
check_invalid_regex RubyRegex::SpanishBankAccountNumber, load_fixture('mac_addresses')['invalid']
end

private
def load_fixture( name )
YAML.load( File.read( File.join( File.dirname(__FILE__), 'fixtures', "#{name}.yml" ) ) )
Expand Down