Class: ListTool::App::ReplaceItemCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/list_tool/app/commands/replace_item_command.rb

Class Method Summary collapse

Methods inherited from Command

ensure_existence_of, fail_if_not_an_array, parse_item_number, parse_item_number!, parse_list_number, parse_list_number!, parse_number

Class Method Details

.execute(options, lister) ⇒ Object

Raises:



20
21
22
23
# File 'lib/list_tool/app/commands/replace_item_command.rb', line 20

def execute options, lister
  args = [ options[:item], options[:name] ]
  raise(ItemNotFoundError, 'no item with given number') if lister.change_item(*args).nil?
end

.helpObject



25
26
27
# File 'lib/list_tool/app/commands/replace_item_command.rb', line 25

def help
  "  r,  replace-item ITEM, TEXT\tSet ITEM text to TEXT"
end

.match?(arg) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/list_tool/app/commands/replace_item_command.rb', line 7

def match? arg
  ['r', 'replace-item'].include? arg
end

.parse(argv) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/list_tool/app/commands/replace_item_command.rb', line 11

def parse argv
  fail_if_not_an_array(argv)

  item, name = argv.shift(2)
  ensure_existence_of('new name' => name)

  { name: name, item: parse_item_number!(item) }
end