120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/input_reader.rb', line 120
def select_items(items, options = {})
prompt_choices(items, options[:selection_attribute])
puts "#{items.size + 1}. All"
input = get_input({
:parsers => [lambda { |input|
choices = input.strip.gsub(/\s*,\s*/, ',').split(',').map(&:to_i)
if choices.include?(items.size + 1)
choices = (1..items.size).to_a
end
choices
}],
:validators => [lambda { |input| input.all? { |i| i > 0 && i <= items.size } }],
:allow_blank => options[:allow_blank],
:prompt => options[:prompt] || 'Choices (separate with comma): '
})
return [] if input.nil?
input.map { |c| items[c - 1] }
end
|