18 lines
503 B
CoffeeScript
18 lines
503 B
CoffeeScript
export default Ember.Object.create
|
|
# go from string:
|
|
# 19, 21-27, 98-101
|
|
# to
|
|
# [19,21,22,23,24,25,26,27,98,99,100,101]
|
|
parse: (identifier) ->
|
|
ids = []
|
|
return ids unless identifier
|
|
String(identifier).replace(/\s/g, '').split(',').forEach (id_spec) ->
|
|
[id_start, id_end] = id_spec.split('-')
|
|
id_start = parseInt(id_start)
|
|
if id_end
|
|
range_result = [id_start..id_end]
|
|
ids = ids.concat range_result
|
|
else
|
|
ids.push id_start
|
|
ids
|