class Frasier::Library
Constants
- LIBRARY_PATH
Attributes
books[RW]
Public Class Methods
library_path()
click to toggle source
# File lib/frasier/library.rb, line 36 def self.library_path LIBRARY_PATH end
new()
click to toggle source
# File lib/frasier/library.rb, line 7 def initialize @books = [] setup @books = find_books! end
Public Instance Methods
book_with_name(name)
click to toggle source
# File lib/frasier/library.rb, line 19 def book_with_name(name) name = Regexp.new(name) books.detect do |book| book.title =~ name || book.path =~ name end end
find_books!()
click to toggle source
# File lib/frasier/library.rb, line 30 def find_books! Dir.glob(File.join(self.class.library_path, "*")).map do |path| Book.new(path) end end
random_book()
click to toggle source
# File lib/frasier/library.rb, line 26 def random_book books.sample end
setup()
click to toggle source
# File lib/frasier/library.rb, line 13 def setup return if File.exist?(self.class.library_path) FileUtils.mkdir_p(self.class.library_path) end