Class: ListTool::App::ReplaceItemCommand
- Inherits:
-
Object
- Object
- ListTool::App::ReplaceItemCommand
- Defined in:
- lib/list_tool/app/commands/replace_item_command.rb
Class Method Summary collapse
Class Method Details
.execute(options, lister) ⇒ Object
22 23 24 25 |
# File 'lib/list_tool/app/commands/replace_item_command.rb', line 22 def self.execute , lister args = [ [:item], [:name] ] raise(ItemNotFoundError, 'no item with given number') if lister.change_item(*args).nil? end |
.help ⇒ Object
27 28 29 |
# File 'lib/list_tool/app/commands/replace_item_command.rb', line 27 def self.help " r, replace-item ITEM, TEXT\tSet ITEM text to TEXT" end |
.match?(arg) ⇒ Boolean
6 7 8 |
# File 'lib/list_tool/app/commands/replace_item_command.rb', line 6 def self.match? arg ['r', 'replace-item'].include? arg end |
.parse(argv) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/list_tool/app/commands/replace_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, name = argv.shift(2) raise ArgumentError, 'item number not specified' if item.nil? raise ArgumentError, 'new name not specified' if name.nil? item = Integer(item) - 1 rescue raise(ArgumentError, 'item number must be an integer') raise ArgumentError, "item number can't be less than 1" if item < 0 {name: name, item: item} end |