Class: Alx::Library

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

Instance Method Summary collapse

Constructor Details

#initializeLibrary

Returns a new instance of Library.



6
7
8
# File 'lib/alx/library.rb', line 6

def initialize
  @books = []
end

Instance Method Details

#list(pattern) ⇒ Object



20
21
22
# File 'lib/alx/library.rb', line 20

def list( pattern )
  @books.select { | book | book.title=~/#{pattern}/ }
end

#load_library(directory) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/alx/library.rb', line 10

def load_library( directory )
  Dir.open( directory ) do | dir |
    files = dir.entries.keep_if { | i | i !~ /^\./ }
    files.each do | file |
      @books << Book.new( file.gsub( /_/, " " ), "#{directory}/#{file}" )
    end
  end
  self
end