Class: Alx::Library
- Inherits:
-
Object
- Object
- Alx::Library
- Defined in:
- lib/alx/library.rb
Instance Method Summary collapse
-
#initialize ⇒ Library
constructor
A new instance of Library.
- #list(pattern) ⇒ Object
- #load_library(directory) ⇒ Object
Constructor Details
#initialize ⇒ Library
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 |