Implement device module with getDisplayName()

This commit is contained in:
Juan Cruz Viotti 2014-11-19 08:45:56 -04:00
parent 8c56d1bbf1
commit f0e1effc05
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,7 @@
{
"Raspberry Pi": [
"raspberry-pi",
"raspberrypi",
"rpi"
]
}

8
lib/device/device.coffee Normal file
View File

@ -0,0 +1,8 @@
_ = require('lodash')
DEVICE_NAMES = require('./device-names.json')
exports.getDisplayName = (device) ->
for key, value of DEVICE_NAMES
if _.indexOf(value, device) isnt -1
return key

View File

@ -0,0 +1,18 @@
expect = require('chai').expect
device = require('./device')
describe 'Device:', ->
describe '#getDisplayName()', ->
it 'should return Raspberry Pi for that device', ->
displayName = 'Raspberry Pi'
possibleNames = [
'raspberry-pi'
'raspberrypi'
'rpi'
]
for name in possibleNames
expect(device.getDisplayName(name)).to.equal(displayName)