Class: ListTool::App::Command

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

Class Method Summary collapse

Class Method Details

.ensure_existence_of(hash) ⇒ Object



35
36
37
38
39
# File 'lib/list_tool/app/commands/command.rb', line 35

def ensure_existence_of hash
  hash.each do |key, value|
    raise ArgumentError, "#{key} not specified" if value.nil?
  end
end

.fail_if_not_an_array(arg) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
# File 'lib/list_tool/app/commands/command.rb', line 41

def fail_if_not_an_array arg
  raise ArgumentError, "expected argument to be an array, #{arg.class} given" unless arg.is_a? Array
end

.parse_item_number(str) ⇒ Object



15
16
17
# File 'lib/list_tool/app/commands/command.rb', line 15

def parse_item_number str
  parse_number(str, "item")
end

.parse_item_number!(str) ⇒ Object

Raises:

  • (ArgumentError)


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

def parse_item_number! str
  raise ArgumentError, 'item number not specified' if str.nil?
  parse_item_number(str)
end

.parse_list_number(str) ⇒ Object



19
20
21
# File 'lib/list_tool/app/commands/command.rb', line 19

def parse_list_number str
  parse_number(str, "list")
end

.parse_list_number!(str) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
# File 'lib/list_tool/app/commands/command.rb', line 29

def parse_list_number! str
  raise ArgumentError, 'list number not specified' if str.nil?
  parse_list_number(str)
end

.parse_number(str, name) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/list_tool/app/commands/command.rb', line 8

def parse_number str, name
  index = Integer(str) - 1 rescue raise(ArgumentError, "#{name} number must be an integer")
  raise ArgumentError, "#{name} number can't be less than 1" if index < 0
  index
end