Module: MyManga
- Defined in:
- lib/my_manga.rb,
lib/my_manga/add.rb,
lib/my_manga/cli.rb,
lib/my_manga/env.rb,
lib/my_manga/find.rb,
lib/my_manga/list.rb,
lib/my_manga/mark.rb,
lib/my_manga/zine.rb,
lib/my_manga/remove.rb,
lib/my_manga/update.rb,
lib/my_manga/command.rb,
lib/my_manga/version.rb,
lib/my_manga/download.rb,
lib/my_manga/m_clean_up.rb
Defined Under Namespace
Modules: CLI
Constant Summary collapse
- VERSION =
'3.0.0'
Class Method Summary collapse
- .[](name) ⇒ Object
- .add(uri) ⇒ Object
- .add_to_zine(names) ⇒ Object
- .create_manga_download_dir(manga) ⇒ Object
- .download(manga, numbers) ⇒ Object
- .download_chapter(chapter, download_dir) ⇒ Object
- .fetch_chapters(manga, numbers) ⇒ Object
- .find(search) ⇒ Object
- .mangdown_client_clean_up ⇒ Object
- .names ⇒ Object
- .package(dir) ⇒ Object
- .read!(manga, numbers) ⇒ Object
- .remove(name) ⇒ Object
- .remove_from_zine(names) ⇒ Object
- .set_read(manga, numbers, bool) ⇒ Object
- .unread!(manga, numbers) ⇒ Object
- .update(manga) ⇒ Object
- .zine ⇒ Object
Class Method Details
.[](name) ⇒ Object
13 14 15 |
# File 'lib/my_manga.rb', line 13 def [](name) Manga.find_by(name: name) end |
.add(uri) ⇒ Object
41 42 43 44 45 46 |
# 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) ⇒ Object
29 30 31 |
# 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) ⇒ Object
107 108 109 110 111 112 113 |
# 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) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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) ⇒ Object
72 73 74 75 76 77 |
# 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) ⇒ Object
52 53 54 |
# File 'lib/my_manga.rb', line 52 def fetch_chapters(manga, numbers) manga.chapters.where(number: numbers) end |
.find(search) ⇒ Object
17 18 19 |
# File 'lib/my_manga.rb', line 17 def find(search) Mangdown::Client.find(search) end |
.mangdown_client_clean_up ⇒ Object
93 94 95 |
# File 'lib/my_manga.rb', line 93 def mangdown_client_clean_up Mangdown::Client.index_manga end |
.names ⇒ Object
25 26 27 |
# File 'lib/my_manga.rb', line 25 def names Manga.pluck(:name) end |
.package(dir) ⇒ Object
21 22 23 |
# File 'lib/my_manga.rb', line 21 def package(dir) Mangdown::CBZ.all(dir) end |
.read!(manga, numbers) ⇒ Object
56 57 58 |
# File 'lib/my_manga.rb', line 56 def read!(manga, numbers) set_read(manga, numbers, true) end |
.remove(name) ⇒ Object
48 49 50 |
# File 'lib/my_manga.rb', line 48 def remove(name) Manga.find_by_name(name)&.destroy end |
.remove_from_zine(names) ⇒ Object
33 34 35 |
# 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) ⇒ Object
98 99 100 101 102 103 104 |
# 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) ⇒ Object
60 61 62 |
# File 'lib/my_manga.rb', line 60 def unread!(manga, numbers) set_read(manga, numbers, false) end |
.update(manga) ⇒ Object
64 65 66 67 68 69 70 |
# 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 ⇒ Object
37 38 39 |
# File 'lib/my_manga.rb', line 37 def zine Manga.where(zine: true) end |