Class: MangaHere
- Inherits:
-
Mangdown::Adapter::Base
- Object
- Mangdown::Adapter::Base
- MangaHere
- Defined in:
- lib/mangdown/adapters/manga_here.rb
Constant Summary collapse
- ROOT =
'http://www.mangahere.cc/'.freeze
- CDNS =
[ 'http://l.mhcdn.net/store/manga/', 'https://mhcdn.secure.footprint.net/store/manga/' ].freeze
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
-
#chapter ⇒ Object
Return Hash with keys: :uri, :name, :chapter, :manga, :site.
-
#chapter_list ⇒ Object
Return Array of Hash with keys: :uri, :name, :site.
- #hydra_opts ⇒ Object
-
#initialize(uri, doc, name) ⇒ MangaHere
constructor
A new instance of MangaHere.
-
#is_chapter?(uri = @uri) ⇒ Boolean
Must return true/false if uri represents a chapter for adapter.
-
#is_manga?(uri = @uri) ⇒ Boolean
Must return true/false if uri represents a manga for adapter.
- #is_manga_list?(uri = @uri) ⇒ Boolean
-
#is_page?(uri = @uri) ⇒ Boolean
Must return true/false if uri represents a page for adapter.
-
#manga ⇒ Object
Return Hash with keys: :uri, :name, :site.
-
#manga_list ⇒ Object
Return Array of Hash with keys: :uri, :name, :site.
-
#page ⇒ Object
Return Hash with keys: :uri, :name, :site.
-
#page_list ⇒ Object
Return Array of Hash with keys: :uri, :name, :site.
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
10 11 12 |
# File 'lib/mangdown/adapters/manga_here.rb', line 10 def root @root end |
Class Method Details
.cdn_uri?(uri) ⇒ Boolean
18 19 20 |
# File 'lib/mangdown/adapters/manga_here.rb', line 18 def self.cdn_uri?(uri) CDNS.any? { |cdn| uri.to_s.start_with?(cdn) } end |
.for?(uri_or_site) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/mangdown/adapters/manga_here.rb', line 12 def self.for?(uri_or_site) uri_or_site.to_s.start_with?(ROOT) || cdn_uri?(uri_or_site) || uri_or_site.to_s == 'manga_here' end |
Instance Method Details
#chapter ⇒ Object
Return Hash with keys: :uri, :name, :chapter, :manga, :site
79 80 81 82 83 84 85 |
# File 'lib/mangdown/adapters/manga_here.rb', line 79 def chapter name ||= chapter_name chapter ||= name.slice(/[\d\.]+$/) manga = name.sub(/ #{chapter}\Z/, '').strip { uri: uri, name: name, chapter: chapter, manga: manga, site: site } end |
#chapter_list ⇒ Object
Return Array of Hash with keys: :uri, :name, :site
67 68 69 70 71 72 73 74 75 |
# File 'lib/mangdown/adapters/manga_here.rb', line 67 def chapter_list chapters = doc.css('.manga_detail .detail_list ul').first.css('li a') chapters.reverse.map.with_index do |a, i| uri = URI.join(root, a[:href]).to_s name = a.text.strip { uri: uri, name: name, chapter: i + 1, site: site } end end |
#hydra_opts ⇒ Object
28 29 30 |
# File 'lib/mangdown/adapters/manga_here.rb', line 28 def hydra_opts { max_concurrency: 1 } end |
#is_chapter?(uri = @uri) ⇒ Boolean
Must return true/false if uri represents a chapter for adapter
42 43 44 |
# File 'lib/mangdown/adapters/manga_here.rb', line 42 def is_chapter?(uri = @uri) uri =~ /#{root}.+\/c\d{3}\/?/ end |
#is_manga?(uri = @uri) ⇒ Boolean
Must return true/false if uri represents a manga for adapter
37 38 39 |
# File 'lib/mangdown/adapters/manga_here.rb', line 37 def is_manga?(uri = @uri) uri =~ /#{root}manga\// end |
#is_manga_list?(uri = @uri) ⇒ Boolean
32 33 34 |
# File 'lib/mangdown/adapters/manga_here.rb', line 32 def is_manga_list?(uri = @uri) uri =~ /#{root}mangalist/ end |
#is_page?(uri = @uri) ⇒ Boolean
Must return true/false if uri represents a page for adapter
47 48 49 |
# File 'lib/mangdown/adapters/manga_here.rb', line 47 def is_page?(uri = @uri) self.class.cdn_uri?(uri) end |
#manga ⇒ Object
Return Hash with keys: :uri, :name, :site
60 61 62 63 64 |
# File 'lib/mangdown/adapters/manga_here.rb', line 60 def manga name ||= doc.css('h1.title').first.text.strip { uri: uri, name: name, site: site } end |
#manga_list ⇒ Object
Return Array of Hash with keys: :uri, :name, :site
52 53 54 55 56 57 |
# File 'lib/mangdown/adapters/manga_here.rb', line 52 def manga_list doc.css('.list_manga a.manga_info').map { |a| uri = URI.join(root, a[:href]).to_s { uri: uri, name: a.text.strip, site: site }} end |
#page ⇒ Object
Return Hash with keys: :uri, :name, :site
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mangdown/adapters/manga_here.rb', line 98 def page if name.nil? option = doc.css('.wid60 option[selected]').first name = "#{chapter_name} - #{option.text.strip.rjust(3, '0')}" end image = doc.css('.read_img img')[1] uri = image[:src] { uri: uri, name: name, site: site } end |
#page_list ⇒ Object
Return Array of Hash with keys: :uri, :name, :site
88 89 90 91 92 93 94 95 |
# File 'lib/mangdown/adapters/manga_here.rb', line 88 def page_list doc.css('.wid60').first.css('option').map do |option| uri = URI.join(root, option[:value]).to_s name = option.text { uri: uri, name: name, site: site } end end |