Module: Mangdown::Client

Extended by:
Logging
Defined in:
lib/mangdown/client.rb

Overview

Simple client for Mangdown

Class Method Summary collapse

Class Method Details

.cbz(dir) ⇒ Object

cbz all subdirectories in a directory



26
27
28
29
30
# File 'lib/mangdown/client.rb', line 26

def cbz(dir)
  Mangdown::CBZ.all(dir)
rescue StandardError => error
  raise Mangdown::Error, "Failed to package #{dir}: #{error.message}"
end

.find(search) ⇒ Object

return a list of hash with :uri and :name of mangas found in list



17
18
19
20
21
22
23
# File 'lib/mangdown/client.rb', line 17

def find(search)
  filter = Sequel.lit('LOWER(name) LIKE ?', "%#{search.downcase}%")
  order = Sequel[:name]
  Mangdown::DB::Manga.where(filter).order(order).map do |manga|
    Mangdown.manga(manga.url)
  end
end

.index_mangaObject

rubocop:disable Metrics/MethodLength load manga into sqlite db



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mangdown/client.rb', line 34

def index_manga
  count_before = Mangdown::DB::Manga.count

  Mangdown.adapters.each do |name, adapters|
    adapters.manga_list.each do |manga|
      Mangdown::DB::Manga.find_or_create(
        adapter: name.to_s,
        url: manga.url,
        name: manga.name
      )
    end
  end

  count_after = Mangdown::DB::Manga.count

  logger.info("#{count_after} manga, #{count_after - count_before} new")
end