Module: Qe::ModelExtensions
- Defined in:
- lib/qe/model_extensions.rb
Class Method Summary collapse
-
.next_label(prefix, labels) ⇒ Object
Helper for create a QuestionSheet or Page with the “next unused label” labels => an array of existing label strings prefix => the prefix that default pages/sheet have (ignores labels not matching this format).
Class Method Details
.next_label(prefix, labels) ⇒ Object
Helper for create a QuestionSheet or Page with the “next unused label”
labels => an array of existing label strings
prefix => the prefix that default pages/sheet have (ignores labels not matching this format)
7 8 9 10 11 12 13 14 |
# File 'lib/qe/model_extensions.rb', line 7 def next_label(prefix, labels) max = labels.inject(0) do |max, label| num = label[/^#{prefix} ([0-9]+)$/i, 1].to_i # extract your digits num > max ? num : max end "#{prefix} #{max.next}" end |