Class: ChapterCrawler

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

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.



67
68
69
70
71
72
73
74
# File 'lib/yamd.rb', line 67

def initialize(custom_data, chapter_page, number, manga)
  @custom_data = custom_data
  @url = custom_data[:url]
  @uri = Addressable::URI.heuristic_parse(url)
  @number = number
  @parsed_html = chapter_page
  @manga = manga
end

Instance Attribute Details

#custom_dataObject (readonly)

Returns the value of attribute custom_data.



65
66
67
# File 'lib/yamd.rb', line 65

def custom_data
  @custom_data
end

#mangaObject (readonly)

Returns the value of attribute manga.



65
66
67
# File 'lib/yamd.rb', line 65

def manga
  @manga
end

#numberObject (readonly)

Returns the value of attribute number.



65
66
67
# File 'lib/yamd.rb', line 65

def number
  @number
end

#parsed_htmlObject (readonly)

Returns the value of attribute parsed_html.



65
66
67
# File 'lib/yamd.rb', line 65

def parsed_html
  @parsed_html
end

#uriObject (readonly)

Returns the value of attribute uri.



65
66
67
# File 'lib/yamd.rb', line 65

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url.



65
66
67
# File 'lib/yamd.rb', line 65

def url
  @url
end

Class Method Details

.page_classObject



98
99
100
# File 'lib/yamd.rb', line 98

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

Instance Method Details

#nameObject



80
81
82
# File 'lib/yamd.rb', line 80

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

#pagesObject



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/yamd.rb', line 84

def pages
  Enumerator.new do | yielder |
    number = 1
    pages_info.each do | page_info |
      # fix the url to be absolute
      full_url = @uri.join(page_info[:url]).to_s
      page_info[:url] = full_url
      parsed_html = Nokogiri::HTML(my_open(full_url))
      yielder.yield self.class.page_class.new(page_info, parsed_html, number, self)
      number += 1
    end
  end
end

#pages_infoObject



76
77
78
# File 'lib/yamd.rb', line 76

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