Class: Klipbook::Sources::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/klipbook/sources/source.rb

Class Method Summary collapse

Class Method Details

.build(options) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/klipbook/sources/source.rb', line 4

def self.build(options)
  if options.from_file
    file_source(options.from_file, options.count)
  elsif options.from_site
    site_source(options.from_site, options.count)
  else
    raise "Unknown source type"
  end
end

.file_source(file, max_books) ⇒ Object



25
26
27
# File 'lib/klipbook/sources/source.rb', line 25

def self.file_source(file, max_books)
  Sources::KindleDevice::File.new(File.read(file), max_books)
end

.site_source(credentials, max_books) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/klipbook/sources/source.rb', line 14

def self.site_source(credentials, max_books)
  unless credentials =~ /(.+):(.+)/
    logger.error "Error: your credentials need to be in username:password format."
    exit 127
  end

  username = $1
  password = $2
  Sources::AmazonSite::SiteScraper.new(username, password, max_books)
end