Cleaned up value normalization code
This commit is contained in:
1 parent
8f30fc7d09
commit
56fa1f03e4
3 files changed
+49
-30
No files matched your search
@@ -0,0 +1,39 @@
|
||||
common = require './common'
|
||||
|
||||
|
||||
normalizers = {}
|
||||
|
||||
|
||||
FLOAT_REGEX = /^([\-\+]?[0-9\.]+)/
|
||||
normalizers.float = (input) ->
|
||||
res = FLOAT_REGEX.exec(input)
|
||||
if res != null
|
||||
parseFloat(res[1])
|
||||
else
|
||||
null
|
||||
|
||||
|
||||
exports.normalize = (path, value) ->
|
||||
if path of parameters
|
||||
return normalizers[parameters[path].type](value)
|
||||
else
|
||||
return value
|
||||
|
||||
|
||||
parameters = {
|
||||
'InternetGatewayDevice.WiMAX.Status.RSSI' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.WiMAX.Status.CINR1' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.WiMAX.Status.CINR2' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.X_MTK_WiMAX_Param.CINR_level' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.X_MTK_WiMAX_Param.RSSI_level' : {
|
||||
type : 'float',
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user