module MyManga

Constants

VERSION

Public Instance Methods

[](name) click to toggle source
# File lib/my_manga.rb, line 13
def [](name)
  Manga.find_by(name: name)
end
add(uri) click to toggle source
# File lib/my_manga.rb, line 41
def add(uri)
  return if Manga.find_by_uri(uri)

  md_manga = Mangdown.manga(uri)
  Manga.from_md(md_manga)
end
add_to_zine(names) click to toggle source
# File lib/my_manga.rb, line 29
def add_to_zine(names)
  Manga.where(name: names).update(zine: true)
end
create_manga_download_dir(manga) click to toggle source

@private

# File lib/my_manga.rb, line 107
def create_manga_download_dir(manga)
  base = MyManga.download_dir
  manga_dir = [base, manga.name].join('/')
  Dir.mkdir(base) unless Dir.exist?(base)
  Dir.mkdir(manga_dir) unless Dir.exist?(manga_dir)
  manga_dir
end
download(manga, numbers) click to toggle source
# File lib/my_manga.rb, line 79
def download(manga, numbers)
  unless env == 'test'
    download_dir = create_manga_download_dir(manga)
    chapters = fetch_chapters(manga, numbers)

    chapters.each do |chapter|
      download_chapter(chapter, download_dir)
    end
    package(download_dir)
  end

  read!(manga, numbers)
end
download_chapter(chapter, download_dir) click to toggle source
# File lib/my_manga.rb, line 72
def download_chapter(chapter, download_dir)
  return if env == 'test'

  md_chapter = chapter.to_md
  md_chapter.download_to(download_dir)
end
fetch_chapters(manga, numbers) click to toggle source
# File lib/my_manga.rb, line 52
def fetch_chapters(manga, numbers)
  manga.chapters.where(number: numbers)
end
find(search) click to toggle source
# File lib/my_manga.rb, line 17
def find(search)
  Mangdown::Client.find(search)
end
mangdown_client_clean_up() click to toggle source
# File lib/my_manga.rb, line 93
def mangdown_client_clean_up
  Mangdown::Client.index_manga
end
names() click to toggle source
# File lib/my_manga.rb, line 25
def names
  Manga.pluck(:name)
end
package(dir) click to toggle source
# File lib/my_manga.rb, line 21
def package(dir)
  Mangdown::CBZ.all(dir)
end
read!(manga, numbers) click to toggle source
# File lib/my_manga.rb, line 56
def read!(manga, numbers)
  set_read(manga, numbers, true)
end
remove(name) click to toggle source
# File lib/my_manga.rb, line 48
def remove(name)
  Manga.find_by_name(name)&.destroy
end
remove_from_zine(names) click to toggle source
# File lib/my_manga.rb, line 33
def remove_from_zine(names)
  Manga.where(name: names).update(zine: false)
end
set_read(manga, numbers, bool) click to toggle source

@private

# File lib/my_manga.rb, line 98
def set_read(manga, numbers, bool)
  chapters = fetch_chapters(manga, numbers)
  chapters.update_all(read: bool)
  manga.reload
  manga.read_count = manga.chapters_read.length
  manga.save
end
unread!(manga, numbers) click to toggle source
# File lib/my_manga.rb, line 60
def unread!(manga, numbers)
  set_read(manga, numbers, false)
end
update(manga) click to toggle source
# File lib/my_manga.rb, line 64
def update(manga)
  return if env == 'test'

  md_manga = manga.to_md
  chapters = md_manga.chapters
  manga.update_chapters(chapters)
end
zine() click to toggle source
# File lib/my_manga.rb, line 37
def zine
  Manga.where(zine: true)
end