Class: ListTool::App::DeleteItemCommand
- Inherits:
-
Object
- Object
- ListTool::App::DeleteItemCommand
- Defined in:
- lib/list_tool/app/commands/delete_item_command.rb
Class Method Summary collapse
Class Method Details
.execute(options, lister) ⇒ Object
26 27 28 29 30 |
# File 'lib/list_tool/app/commands/delete_item_command.rb', line 26 def self.execute , lister args = [ [:item] ] args << {list: [:list]} if [:list] raise(ListNotFoundError, 'no list with given number') if lister.delete_item(*args).nil? end |
.help ⇒ Object
32 33 34 |
# File 'lib/list_tool/app/commands/delete_item_command.rb', line 32 def self.help " d, del-item ITEM [LIST]\tDelete ITEM from given or default list" end |
.match?(arg) ⇒ Boolean
6 7 8 |
# File 'lib/list_tool/app/commands/delete_item_command.rb', line 6 def self.match? arg ['d', 'del-item'].include? arg end |
.parse(argv) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/list_tool/app/commands/delete_item_command.rb', line 10 def self.parse argv raise ArgumentError, "expected argument to be an array, #{argv.class} given" unless argv.is_a? Array item, list = argv.shift(2) raise ArgumentError, 'item number not specified' if item.nil? out = {item: Integer(item) - 1} rescue raise(ArgumentError, 'item number must be an integer') if list out[:list] = Integer(list) - 1 rescue raise(ArgumentError, 'list number must be an integer') raise ArgumentError, "list number can't be less than 1" if out[:list] < 0 end out end |