Class: MangafoxChapter

Inherits:
ChapterCrawler show all
Defined in:
lib/yamd/mangafox.rb

Instance Attribute Summary

Attributes inherited from ChapterCrawler

#custom_data, #manga, #number, #parsed_html, #uri, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ChapterCrawler

#initialize, #pages

Constructor Details

This class inherits a constructor from ChapterCrawler

Class Method Details

.page_classObject



11
12
13
# File 'lib/yamd/mangafox.rb', line 11

def self.page_class
  MangafoxPage
end

Instance Method Details

#nameObject



30
31
32
# File 'lib/yamd/mangafox.rb', line 30

def name
  @custom_data[:name]
end

#pages_infoObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/yamd/mangafox.rb', line 15

def pages_info
  # there's no need of an lazy enumerator here, no IO action is taken
  page_options = @parsed_html.at_css('.prev_page + div > select').css('option')
  pages_number = page_options.map { | option | option['value'].to_i }.max
  
  chapter_base_url = Addressable::URI.parse(self.url)
  chapter_base_path, _ = Pathname.new(chapter_base_url.path).split
  page_urls = (1..pages_number).to_a.map do | i |
    chapter_base_url.path = chapter_base_path.join("#{i}.html").to_s
    { url: chapter_base_url.to_s }
  end

  page_urls
end