Class: Alx::AddHandler

Inherits:
Handler show all
Defined in:
lib/alx/add_handler.rb

Instance Attribute Summary

Attributes inherited from Handler

#command_name

Instance Method Summary collapse

Methods inherited from Handler

#help

Constructor Details

#initialize(configuration) ⇒ AddHandler

Returns a new instance of AddHandler.



7
8
9
10
11
12
13
14
# File 'lib/alx/add_handler.rb', line 7

def initialize( configuration )
  super(
    :configuration => configuration,
    :command => 'add',
    :rest_description => 'book title',
    :description => "Adds new book to the library.",
    :options => [ :editor, :stdin ] )
end

Instance Method Details

#handleObject



16
17
18
19
20
21
# File 'lib/alx/add_handler.rb', line 16

def handle
  parse_options
  options_error( "No file name given. Please provide one." ) if @conf[ :rest ].empty?
  book_file_name = @conf[ :default_shelf_dir ] + "/" +@conf[ :rest ].gsub( / /, "_" )
  Editor.new( @conf ).edit( book_file_name )
end