Class: Mangos::BookUpdater
- Inherits:
-
Object
- Object
- Mangos::BookUpdater
- Defined in:
- lib/mangos/book_updater.rb
Instance Attribute Summary collapse
-
#book ⇒ Object
readonly
Returns the value of attribute book.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
Instance Method Summary collapse
- #build_page_paths(page_paths) ⇒ Object
- #find_page_paths ⇒ Object
- #fix_thumbnail_path ⇒ Object
-
#initialize(package, book, path) ⇒ BookUpdater
constructor
A new instance of BookUpdater.
- #thumbnail_path ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(package, book, path) ⇒ BookUpdater
Returns a new instance of BookUpdater.
4 5 6 7 8 |
# File 'lib/mangos/book_updater.rb', line 4 def initialize(package, book, path) @package = package @book = book @path = path end |
Instance Attribute Details
#book ⇒ Object (readonly)
Returns the value of attribute book.
2 3 4 |
# File 'lib/mangos/book_updater.rb', line 2 def book @book end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
2 3 4 |
# File 'lib/mangos/book_updater.rb', line 2 def package @package end |
Instance Method Details
#build_page_paths(page_paths) ⇒ Object
30 31 32 |
# File 'lib/mangos/book_updater.rb', line 30 def build_page_paths(page_paths) Mangos::PagesDeflater.new(page_paths.map { |p| p.basename.to_s }).deflate end |
#find_page_paths ⇒ Object
25 26 27 28 |
# File 'lib/mangos/book_updater.rb', line 25 def find_page_paths image_paths = @path.children.select { |p| p.image? && !p.hidden? } Naturalsorter::Sorter.sort(image_paths.map(&:to_s), true).map { |p| DecoratedPathname.new(p) } end |
#fix_thumbnail_path ⇒ Object
38 39 40 41 42 43 |
# File 'lib/mangos/book_updater.rb', line 38 def fix_thumbnail_path old_thumbnail_path = @package.thumbnails_path + "#{@book.old_key}.jpg" if old_thumbnail_path.exist? && !thumbnail_path.exist? old_thumbnail_path.rename(thumbnail_path) end end |
#thumbnail_path ⇒ Object
34 35 36 |
# File 'lib/mangos/book_updater.rb', line 34 def thumbnail_path @package.thumbnails_path + "#{@book.key}.jpg" end |
#update ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mangos/book_updater.rb', line 10 def update page_paths = find_page_paths @book.old_key = @book.key @book.key = Digest::SHA256.hexdigest(@path.basename.to_s)[0..16] @book.page_paths = build_page_paths(page_paths) @book.pages = page_paths.length @book.path = @path.basename.to_s @book.published_on = @path.mtime.to_i @book. = Mangos::TagBreaker.new(@book.path). fix_thumbnail_path if @package.migrate? Mangos::Thumbnailer.new(page_paths.first, thumbnail_path).generate end |