summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2016-06-05 11:27:05 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2016-06-05 11:27:09 -0300
commiteb07ef69464088f1d068853dbb6594b51d9ed644 (patch)
treee071b98302d4fcdd57781931e14ca7748d12cd1c
parent2593b4581476ba3eca2a35750ed84ca14208394c (diff)
downloadhighline-eb07ef69464088f1d068853dbb6594b51d9ed644.tar.gz
Split and reduce complexity on Menu#options
-rw-r--r--lib/highline/menu.rb25
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb
index 06e3cf9..a942d99 100644
--- a/lib/highline/menu.rb
+++ b/lib/highline/menu.rb
@@ -354,29 +354,30 @@ class HighLine
# This method returns all possible options for auto-completion, based
# on the settings of _index_ and _select_by_.
#
- def options( )
- # add in any hidden menu commands
- items = all_items
-
+ def options
case @select_by
- when :index then
- map_items_by_index(items, @index)
+ when :index
+ map_items_by_index
when :name
- items.map(&:name)
+ map_items_by_name
else
- map_items_by_index(items, @index) + items.map(&:name)
+ map_items_by_index + map_items_by_name
end
end
- def map_items_by_index(items, index = nil)
- if index == :letter
+ def map_items_by_index
+ if @index == :letter
l_index = "`"
- items.map { "#{l_index.succ!}" }
+ all_items.map { "#{l_index.succ!}" }
else
- (1 .. items.size).map(&:to_s)
+ (1..all_items.size).map(&:to_s)
end
end
+ def map_items_by_name
+ all_items.map(&:name)
+ end
+
def all_items
@items + @hidden_items
end