class HammerCLI::Help::Definition
Public Instance Methods
at(path)
click to toggle source
Calls superclass method
# File lib/hammer_cli/help/definition.rb, line 23 def at(path) return super(path) if path.is_a? Integer return self if path.empty? expand_path(path) end
build_string()
click to toggle source
# File lib/hammer_cli/help/definition.rb, line 9 def build_string @out = StringIO.new each do |item| next unless item.is_a? AbstractItem @out.puts unless first_print? @out.puts item.build_string end @out.string end
find_item(item_id)
click to toggle source
# File lib/hammer_cli/help/definition.rb, line 19 def find_item(item_id) self[item_index(item_id)] end
insert_definition(mode, item_id, definition)
click to toggle source
# File lib/hammer_cli/help/definition.rb, line 29 def insert_definition(mode, item_id, definition) HammerCLI.insert_relative(self, mode, item_index(item_id), *definition) end
Private Instance Methods
expand_path(path)
click to toggle source
# File lib/hammer_cli/help/definition.rb, line 35 def expand_path(path) path = [path] unless path.is_a? Array item = find_item(path[0]) return item if path[1..-1].empty? item.definition.at(path[1..-1]) end
first_print?()
click to toggle source
# File lib/hammer_cli/help/definition.rb, line 42 def first_print? @out.size.zero? end
item_index(item_id)
click to toggle source
# File lib/hammer_cli/help/definition.rb, line 46 def item_index(item_id) index = find_index do |item| item.id == item_id end raise ArgumentError, "Help item '#{item_id}' not found" if index.nil? index end