-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying whether person of colour by DM
Progress toward #6
- Loading branch information
Showing
5 changed files
with
148 additions
and
10 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,35 @@ | ||
class RaceUpdateParser { | ||
constructor(message) { | ||
this.message = message.toLowerCase(); | ||
} | ||
|
||
parseIsPersonOfColour() { | ||
if (this.matchesPersonOfColourPatterns()) { | ||
return true; | ||
} else if (this.matchesNotPersonOfColourPatterns()) { | ||
return false; | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
|
||
matchesPersonOfColourPatterns() { | ||
if ((this.message.match(/person of colou?r/) && !this.message.match(/not/)) || | ||
(this.message.match(/white/) && this.message.match(/not/))) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
matchesNotPersonOfColourPatterns() { | ||
if ((this.message.match(/person of colou?r/) && this.message.match(/not/)) || | ||
(this.message.match(/white/) && !this.message.match(/not/))) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
module.exports = RaceUpdateParser; |
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,25 @@ | ||
#!/usr/bin/env iojs --es_staging --use-strict | ||
|
||
var test = require('tape'); | ||
|
||
var RaceUpdateParser = require('../src/race-update-parser'); | ||
|
||
test('RaceUpdateParser parses whether or not someone is a person of colour', function(t) { | ||
var inputToResponse = { | ||
'i am a Person of Colour': true, | ||
'person of color': true, | ||
'i am not a person of color': false, | ||
'i am white': false, | ||
'i am not white': true, | ||
'anything': undefined | ||
}; | ||
|
||
Object.keys(inputToResponse).forEach(function(input) { | ||
var parser = new RaceUpdateParser(input); | ||
var response = parser.parseIsPersonOfColour(); | ||
|
||
t.equal(response, inputToResponse[input], `${input} should represent isPersonOfColour ${inputToResponse[input]} but response was ${response}`); | ||
}); | ||
|
||
t.end(); | ||
}); |
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