Class: MangaCrawler

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(manga_main_page_url) ⇒ MangaCrawler

Returns a new instance of MangaCrawler.



106
107
108
109
110
# File 'lib/yamd.rb', line 106

def initialize(manga_main_page_url)
  @url = manga_main_page_url
  @uri = Addressable::URI.heuristic_parse(url)
  @parsed_html = Nokogiri::HTML(my_open(manga_main_page_url))
end

Instance Attribute Details

#parsed_htmlObject

Returns the value of attribute parsed_html.



104
105
106
# File 'lib/yamd.rb', line 104

def parsed_html
  @parsed_html
end

#uriObject

Returns the value of attribute uri.



104
105
106
# File 'lib/yamd.rb', line 104

def uri
  @uri
end

#urlObject

Returns the value of attribute url.



104
105
106
# File 'lib/yamd.rb', line 104

def url
  @url
end

Class Method Details

.chapter_classObject



134
135
136
# File 'lib/yamd.rb', line 134

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

Instance Method Details

#chaptersObject



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/yamd.rb', line 116

def chapters
  Enumerator.new do | yielder |
    number = 1
    chapters_info.each do | chapter_info |
      # fix the url to be absolute
      full_url = @uri.join(chapter_info[:url]).to_s
      chapter_info[:url] = full_url
      page = Nokogiri::HTML(my_open(full_url))
      yielder.yield self.class.chapter_class.new(chapter_info, page, number, self)
      number += 1
    end
  end
end

#chapters_infoObject



112
113
114
# File 'lib/yamd.rb', line 112

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

#nameObject



130
131
132
# File 'lib/yamd.rb', line 130

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