Method: WordTree::BookList#iterable_from_source

Defined in:
lib/wordtree/book_list.rb

#iterable_from_source(source) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wordtree/book_list.rb', line 15

def iterable_from_source(source)
  case source
  when WordTree::Disk::Library then
    source
  when File then
    source.read.split("\n").tap do |file|
      file.close
    end
  when String then
    if File.directory?(source)
      WordTree::Disk::Library.new(source)
    elsif File.exist?(source)
      IO.read(source).split("\n")
    else
      raise Errno::ENOENT, "Unable to find source for BookList, #{source.inspect}"
    end
  end
end