Class: Alx::RemoveHandler

Inherits:
Handler
  • Object
show all
Defined in:
lib/alx/remove_handler.rb

Instance Attribute Summary

Attributes inherited from Handler

#command_name

Instance Method Summary collapse

Methods inherited from Handler

#help

Constructor Details

#initialize(configuration) ⇒ RemoveHandler

Returns a new instance of RemoveHandler.



6
7
8
9
10
11
12
# File 'lib/alx/remove_handler.rb', line 6

def initialize( configuration )
  super(
    :configuration => configuration,
    :command => 'remove',
    :rest_description => 'pattern',
    :description => "Removes matching books from the library." )
end

Instance Method Details

#handleObject



14
15
16
17
18
19
20
# File 'lib/alx/remove_handler.rb', line 14

def handle
  parse_options
  options_error( "No pattern given. Please provide one." ) if @conf[ :rest ].empty?
  matching_books = load_library.list( @conf[ :rest ] )
  return remove_book( matching_books.pop ) if matching_books.size == 1
  matching_books.each { | book | remove_book( book ) if ask?( "Do you really want to remove #{book.title}?" ) }
end