Class: Alx::RemoveHandler
Instance Attribute Summary
Attributes inherited from Handler
Instance Method Summary collapse
- #handle ⇒ Object
-
#initialize(configuration) ⇒ RemoveHandler
constructor
A new instance of RemoveHandler.
Methods inherited from Handler
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
#handle ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/alx/remove_handler.rb', line 14 def handle ( "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 |