Class: ListTool::App::AddItemCommand
- Inherits:
-
Object
- Object
- ListTool::App::AddItemCommand
- Defined in:
- lib/list_tool/app/commands/add_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/add_item_command.rb', line 26 def self.execute , lister args = [ .delete(:text) ] args << if [:list] raise(ListNotFoundError, 'no list with given number') if lister.add_item(*args).nil? end |
.help ⇒ Object
32 33 34 |
# File 'lib/list_tool/app/commands/add_item_command.rb', line 32 def self.help " a, add-item TEXT [LIST]\tAdd item with TEXT to given or default list" end |
.match?(arg) ⇒ Boolean
6 7 8 |
# File 'lib/list_tool/app/commands/add_item_command.rb', line 6 def self.match? arg ['a', 'add-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/add_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 text not specified' if item.nil? out = {text: item} 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 |