Class: ChapterCrawler

Inherits:
Object
  • Object
show all
Defined in:
lib/yamd.rb

Direct Known Subclasses

FakkuChapter, MangafoxChapter, MangahereChapter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_data, chapter_page, number, manga) ⇒ ChapterCrawler

Returns a new instance of ChapterCrawler.



42
43
44
45
46
47
48
# File 'lib/yamd.rb', line 42

def initialize(custom_data, chapter_page, number, manga)
  @custom_data = custom_data
  @url = custom_data[:url]
  @number = number
  @parsed_html = chapter_page
  @manga = manga
end

Instance Attribute Details

#custom_dataObject (readonly)

Returns the value of attribute custom_data.



40
41
42
# File 'lib/yamd.rb', line 40

def custom_data
  @custom_data
end

#mangaObject (readonly)

Returns the value of attribute manga.



40
41
42
# File 'lib/yamd.rb', line 40

def manga
  @manga
end

#numberObject (readonly)

Returns the value of attribute number.



40
41
42
# File 'lib/yamd.rb', line 40

def number
  @number
end

#parsed_htmlObject (readonly)

Returns the value of attribute parsed_html.



40
41
42
# File 'lib/yamd.rb', line 40

def parsed_html
  @parsed_html
end

#urlObject (readonly)

Returns the value of attribute url.



40
41
42
# File 'lib/yamd.rb', line 40

def url
  @url
end

Class Method Details

.page_classObject



69
70
71
# File 'lib/yamd.rb', line 69

def self.page_class
  fail 'This method is abstract and have to be defined in a subclass.'
end

Instance Method Details

#nameObject



54
55
56
# File 'lib/yamd.rb', line 54

def name
  fail 'This method is abstract and have to be defined in a subclass.'
end

#pagesObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/yamd.rb', line 58

def pages
  Enumerator.new do | yielder |
    number = 1
    pages_info.each do | page_info |
      parsed_html = Nokogiri::HTML(my_open(page_info[:url]))
      yielder.yield self.class.page_class.new(page_info, parsed_html, number, self)
      number += 1
    end
  end
end

#pages_infoObject



50
51
52
# File 'lib/yamd.rb', line 50

def pages_info
  fail 'This method is abstract and have to be defined in a subclass.'
end