Class: EbookLibrary::Gatherer

Inherits:
Object
  • Object
show all
Defined in:
lib/ebook_library/gatherer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = EbookLibrary.default_path) ⇒ Gatherer

Returns a new instance of Gatherer.

Raises:



11
12
13
14
# File 'lib/ebook_library/gatherer.rb', line 11

def initialize(path=EbookLibrary.default_path)
  @path = path if File.exist?(path)
  raise InvalidPath if @path.nil?
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/ebook_library/gatherer.rb', line 9

def path
  @path
end

Instance Method Details

#gatherObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ebook_library/gatherer.rb', line 16

def gather
  results = gather_ebooks.map do |book_path|
    begin
      ebook = Ebook.new(book_path)
      ebook.to_hash
    rescue EbookLibrary::UnsupportedFormatError
      puts "skipping: " + book_path
    end
  end
  { books: results.compact }
end