-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Zenedith/numberplates-data
Added information about plate and real validators
- Loading branch information
Showing
13 changed files
with
380 additions
and
34 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//http://pl.wikipedia.org/wiki/Polskie_tablice_rejestracyjne | ||
var formats = []; | ||
|
||
formats['2CT5D'] = '[A-Z]{2}[0-9]{5}'; // XY 12345 | ||
formats['2CT4D1C'] = '[A-Z]{2}[0-9]{4}[A-Z]{1}'; // XY 1234A | ||
formats['2CT3D2C'] = '[A-Z]{2}[0-9]{3}[A-Z]{2}'; // XY 123AC | ||
formats['2CT1D1C3D'] = '[A-Z]{2}[0-9]{1}[A-Z]{1}[0-9]{3}'; // XY 1A234 | ||
formats['2CT1D2C2D'] = '[A-Z]{2}[0-9]{1}[A-Z]{2}[0-9]{2}'; // XY 1AC23 | ||
|
||
formats['3CT1C3D'] = '[A-Z]{4}[0-9]{3}'; // XYZ A123 | ||
formats['3CT2D2C'] = '[A-Z]{3}[0-9]{2}[A-Z]{2}'; // XYZ 12AC | ||
formats['3CT1D1C2D'] = '[A-Z]{3}[0-9]{1}[A-Z]{1}[0-9]{2}'; // XYZ 1A23 | ||
formats['3CT2D1C1D'] = '[A-Z]{3}[0-9]{2}[A-Z]{1}[0-9]{1}'; // XYZ 12A3 | ||
formats['3CT1D2C1D'] = '[A-Z]{3}[0-9]{1}[A-Z]{2}[0-9]{1}'; // XYZ 1AC2 | ||
formats['3CT2C2D'] = '[A-Z]{5}[0-9]{2}'; // XYZ AC12 | ||
formats['3CT5D'] = '[A-Z]{3}[0-9]{5}'; // XYZ 12345 | ||
formats['3CT4D1C'] = '[A-Z]{3}[0-9]{4}[A-Z]{1}'; // XYZ 1234A | ||
formats['3CT3D2C'] = '[A-Z]{3}[0-9]{3}[A-Z]{2}'; // XYZ 123AC | ||
formats['3CT1C2D1C'] = '[A-Z]{4}[0-9]{2}[A-Z]{1}'; // XYZ A12C | ||
formats['3CT1C1D2C'] = '[A-Z]{4}[0-9]{1}[A-Z]{2}'; // XYZ A1CE | ||
|
||
formats['2CT2D1C'] = '[A-Z]{2}[0-9]{2}[A-Z]{1}'; // HIST2-1 | ||
formats['2CT3D'] = '[A-Z]{2}[0-9]{3}'; // HIST2-2 | ||
|
||
formats['3CT1D1C'] = '[A-Z]{3}[0-9]{1}[A-Z]{1}'; // HIST3-1 | ||
formats['3CT2D'] = '[A-Z]{3}[0-9]{2}'; // HIST3-2 | ||
formats['3CT1C1D'] = '[A-Z]{4}[0-9]{1}'; // HIST3-2 | ||
|
||
formats['1CT1D3C'] = '[A-Z]{1}[0-9]{1}[A-Z]{3}'; // X0 ABC | ||
formats['1CT1D2C1D'] = '[A-Z]{1}[0-9]{1}[A-Z]{2}[0-9]{1}'; // X0 AB1 | ||
formats['1CT1D1C1D'] = '[A-Z]{1}[0-9]{1}[A-Z]{1}[0-9]{2}'; // X0 A12 | ||
|
||
formats['1CT1D4C'] = '[A-Z]{1}[0-9]{1}[A-Z]{4}'; // X0 ABCD | ||
formats['1CT1D3C1D'] = '[A-Z]{1}[0-9]{1}[A-Z]{3}[0-9]{1}'; // X0 ABC1 | ||
formats['1CT1D2C2D'] = '[A-Z]{1}[0-9]{1}[A-Z]{2}[0-9]{2}'; // X0 AB12 | ||
|
||
formats['1CT1D5C'] = '[A-Z]{1}[0-9]{1}[A-Z]{5}'; // X0 ABCDE | ||
formats['1CT1D4C1D'] = '[A-Z]{1}[0-9]{1}[A-Z]{4}[0-9]{1}'; // X0 ABCD1 | ||
formats['1CT1D3C2D'] = '[A-Z]{1}[0-9]{1}[A-Z]{3}[0-9]{2}'; // X0 ABC12 | ||
|
||
|
||
module.exports.getFormat = function (input) { | ||
for (var k in formats) { | ||
if (formats.hasOwnProperty(k)) { | ||
var v = '^' + formats[k] + '$'; | ||
if (input.match(String(v))) { | ||
return k; | ||
} | ||
} | ||
} | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var Location = function Location(state, country) { | ||
this.state = state; | ||
this.country = country; | ||
}; | ||
|
||
var LocationBuilder = function LocationBuilder() { | ||
this.state = null; | ||
this.country = null; | ||
|
||
var self = this; | ||
|
||
this.withState = function (state) { | ||
self.state = state; | ||
return self; | ||
}; | ||
|
||
this.withCountry = function (country) { | ||
self.country = country; | ||
return self; | ||
}; | ||
|
||
this.build = function () { | ||
return new Location(self.state, self.country); | ||
}; | ||
|
||
}; | ||
|
||
module.exports = exports = { | ||
Location: Location, | ||
LocationBuilder: LocationBuilder | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var Plate = function Plate(plate, prefix, number, location) { | ||
this.plate = plate; | ||
this.prefix = prefix; | ||
this.number = number; | ||
this.location = location; | ||
}; | ||
|
||
var PlateBuilder = function PlateBuilder() { | ||
this.plate = null; | ||
this.prefix = null; | ||
this.number = null; | ||
this.location = null; | ||
|
||
var self = this; | ||
|
||
this.withPlate = function (plate) { | ||
self.plate = plate; | ||
return self; | ||
}; | ||
|
||
this.withPrefix = function (prefix) { | ||
self.prefix = prefix; | ||
return self; | ||
}; | ||
|
||
this.withNumber = function (number) { | ||
self.number = number; | ||
return self; | ||
}; | ||
|
||
this.withLocation = function (location) { | ||
self.location = location; | ||
return self; | ||
}; | ||
|
||
this.build = function () { | ||
return new Plate(self.plate, self.prefix, self.number, self.location); | ||
}; | ||
|
||
}; | ||
|
||
module.exports = exports = { | ||
Plate: Plate, | ||
PlateBuilder: PlateBuilder | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var plateModel = require('../lib/model/plate'); | ||
var locationModel = require('../lib/model/location'); | ||
var states = require('../lib/states'); | ||
var formats = require('../lib/formats'); | ||
|
||
module.exports.getPlate = function (input) { | ||
var format = formats.getFormat(input); | ||
|
||
if (!format) { | ||
return null; | ||
} | ||
|
||
var separatorIndex = format.charAt(0); | ||
|
||
var prefix = input.substr(0, separatorIndex); | ||
var number = input.substr(separatorIndex); | ||
var plate = prefix + ' ' + number; | ||
|
||
var state = states.getState(plate); | ||
var location = null; | ||
|
||
if (state) { | ||
new locationModel.LocationBuilder() | ||
.withState(state) | ||
.withCountry('pl-PL') | ||
.build(); | ||
} | ||
|
||
return new plateModel.PlateBuilder() | ||
.withPlate(plate) | ||
.withPrefix(prefix) | ||
.withNumber(number) | ||
.withLocation(location) | ||
.build(); | ||
|
||
}; | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//http://pl.wikipedia.org/wiki/Polskie_tablice_rejestracyjne | ||
var states = { | ||
B: 'podlaskie', | ||
C: 'kujawsko-pomorskie', | ||
D: 'dolnośląskie', | ||
E: 'łódzkie', | ||
F: 'lubuskie', | ||
G: 'pomorskie', | ||
K: 'małopolskie', | ||
L: 'lubelskie', | ||
N: 'warmińsko-mazurskie', | ||
O: 'opolskie', | ||
P: 'wielkopolskie', | ||
R: 'podkarpackie', | ||
S: 'śląskie', | ||
T: 'świętokrzyskie', | ||
W: 'mazowieckie', | ||
Z: 'zachodniopomorskie' | ||
}; | ||
|
||
module.exports.getState = function getState(input) { | ||
var state = input.charAt(0); | ||
|
||
if (states.hasOwnProperty(state)) { | ||
return states[state]; | ||
} | ||
|
||
return null; | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var chai = require('chai'); | ||
var should = chai.should(); | ||
var location = require('../../lib/model/location'); | ||
|
||
describe('location model test', function () { | ||
|
||
it('should create model', function (done) { | ||
|
||
var locationModel = new location.Location('wielkopolskie', 'pl-PL'); | ||
should.exist(locationModel); | ||
locationModel.state.should.be.equal('wielkopolskie'); | ||
locationModel.country.should.be.equal('pl-PL'); | ||
|
||
done(); | ||
}); | ||
|
||
it('should create model by builder', function (done) { | ||
|
||
var locationModel = new location.LocationBuilder() | ||
.withState('wielkopolskie') | ||
.withCountry('pl-PL') | ||
.build(); | ||
|
||
should.exist(locationModel); | ||
locationModel.state.should.be.equal('wielkopolskie'); | ||
locationModel.country.should.be.equal('pl-PL'); | ||
|
||
done(); | ||
}); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var chai = require('chai'); | ||
var should = chai.should(); | ||
var plate = require('../../lib/model/plate'); | ||
|
||
describe('format model test', function () { | ||
|
||
it('should create model', function (done) { | ||
|
||
var formatModel = new plate.Plate('plate', 'prefix', 'number', {state: 'state', country: 'country'}); | ||
should.exist(formatModel); | ||
formatModel.plate.should.be.equal('plate'); | ||
formatModel.prefix.should.be.equal('prefix'); | ||
formatModel.number.should.be.equal('number'); | ||
should.exist(formatModel.location); | ||
formatModel.location.state.should.be.equal('state'); | ||
formatModel.location.country.should.be.equal('country'); | ||
|
||
done(); | ||
}); | ||
|
||
it('should create model by builder', function (done) { | ||
|
||
var formatModel = new plate.PlateBuilder() | ||
.withPlate('plate') | ||
.withPrefix('prefix') | ||
.withNumber('number') | ||
.withLocation({state: 'state', country: 'country'}) | ||
.build(); | ||
|
||
should.exist(formatModel); | ||
formatModel.plate.should.be.equal('plate'); | ||
formatModel.prefix.should.be.equal('prefix'); | ||
formatModel.number.should.be.equal('number'); | ||
should.exist(formatModel.location); | ||
formatModel.location.state.should.be.equal('state'); | ||
formatModel.location.country.should.be.equal('country'); | ||
|
||
done(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.