lib/interactive/options.rb in interactive-0.1.0 vs lib/interactive/options.rb in interactive-0.2.0

- old
+ new

@@ -14,16 +14,28 @@ def shortcuts_string "[#{first_chars_without_last_slash(first_chars)}]" end def shortcuts_meanings - options.inject("") { |accum, opt| "#{accum} #{opt.shortcut_value} -- #{opt}\n"} + options.inject("") { |accum, opt| "#{accum} #{opt.shortcut_value} -- #{opt.value}\n"} end + def has_hash? + @options.any? {|opt| opt.respond_to?(:to_hash) } + end + private def flatten_ranges(options) - @options = options.inject([]) {|accum, opt| opt.respond_to?(:to_a) ? accum | opt.to_a : accum << opt} + @options = options.inject([]) do |accum, opt| + if opt.class == Range + accum | opt.to_a + elsif opt.respond_to?(:to_a) + accum | opt.map.with_index {|item, index| {index.to_s => item} } + else + accum << opt + end + end end def wrap_each_option @options.map! {|option| Option(option) } end