Class: ChapterCrawler

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

Direct Known Subclasses

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.



25
26
27
28
29
30
31
# File 'lib/yamd.rb', line 25

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.



23
24
25
# File 'lib/yamd.rb', line 23

def custom_data
  @custom_data
end

#mangaObject (readonly)

Returns the value of attribute manga.



23
24
25
# File 'lib/yamd.rb', line 23

def manga
  @manga
end

#numberObject (readonly)

Returns the value of attribute number.



23
24
25
# File 'lib/yamd.rb', line 23

def number
  @number
end

#parsed_htmlObject (readonly)

Returns the value of attribute parsed_html.



23
24
25
# File 'lib/yamd.rb', line 23

def parsed_html
  @parsed_html
end

#urlObject (readonly)

Returns the value of attribute url.



23
24
25
# File 'lib/yamd.rb', line 23

def url
  @url
end

Class Method Details

.page_classObject



52
53
54
# File 'lib/yamd.rb', line 52

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

Instance Method Details

#nameObject



37
38
39
# File 'lib/yamd.rb', line 37

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

#pagesObject



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

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

#pages_infoObject



33
34
35
# File 'lib/yamd.rb', line 33

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