Class: Mangdown::Adapter::Base

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

Direct Known Subclasses

Mangafox, Mangahere, Mangareader, Wiemanga

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, doc) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mangdown/adapter.rb', line 6

def initialize(uri, doc)
  @uri, @doc = uri, doc
  #@root                  = '' 
  #@manga_list_css        = ''
  #@chapter_list_css      = ''
  #@manga_name_css        = ''
  #@manga_list_uri        = '' 
  #@manga_link_prefix     = '' 
  #@reverse_chapters      = true || false
  #@manga_uri_regex       = /.*/i 
  #@chapter_uri_regex     = /.*/i
  #@page_uri_regex        = /.*/i
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/mangdown/adapter.rb', line 5

def root
  @root
end

Instance Method Details

#build_page_uri(uri, manga, chapter, page_num) ⇒ Object

Must return a uri for a page given the arguments



45
46
# File 'lib/mangdown/adapter.rb', line 45

def build_page_uri(uri, manga, chapter, page_num)
end

#is_chapter?(uri = @uri) ⇒ Boolean

Must return true/false if uri represents a chapter for adapter

Returns:

  • (Boolean)


30
31
32
# File 'lib/mangdown/adapter.rb', line 30

def is_chapter?(uri = @uri)
  uri.slice(@chapter_uri_regex) == uri
end

#is_manga?(uri = @uri) ⇒ Boolean

Must return true/false if uri represents a manga for adapter

Returns:

  • (Boolean)


25
26
27
# File 'lib/mangdown/adapter.rb', line 25

def is_manga?(uri = @uri)
  uri.slice(@manga_uri_regex) == uri
end

#is_page?(uri = @uri) ⇒ Boolean

Must return true/false if uri represents a page for adapter

Returns:

  • (Boolean)


35
36
37
# File 'lib/mangdown/adapter.rb', line 35

def is_page?(uri = @uri)
  uri.slice(@page_uri_regex) == uri
end

#manga_chaptersObject

If no block given, must return an array arrays

chapter_uri, chapter_name, adapter_type

If block given, then the block may alter this array Only valid chapters should be returned (using is_chapter?(uri))



76
77
78
79
80
81
82
83
# File 'lib/mangdown/adapter.rb', line 76

def manga_chapters
  chapters = doc.css(@chapter_list_css).map { |a|
    chapter = [(root + a[:href].sub(root, '')),a.text.strip,type]
    next(nil) unless is_chapter?(chapter.first)
    block_given? ? yield(chapter) : chapter 
  }.compact
  @reverse_chapters ? chapters.reverse : chapters
end

#manga_listObject

If no block given, must return an array arrays

manga_uri, manga_name, adapter_type

If block given, then the block may alter this array Only valid mangas should be returned (using is_manga?(uri))



64
65
66
67
68
69
70
# File 'lib/mangdown/adapter.rb', line 64

def manga_list
  doc.css(@manga_list_css).map { |a| 
    manga = ["#{@manga_link_prefix}#{a[:href]}",a.text.strip,type]
    next(nil) unless is_manga?(manga.first)
    block_given? ? yield(manga) : manga
  }.compact
end

#manga_nameObject

Must return a string



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

def manga_name
  doc.css(@manga_name_css).text
end

#num_pagesObject

Must return the number of pages for a chapter



49
50
# File 'lib/mangdown/adapter.rb', line 49

def num_pages
end

#page_image_nameObject

Must return the name of the page image



57
58
# File 'lib/mangdown/adapter.rb', line 57

def page_image_name
end

#page_image_srcObject

Must return the src for the page image



53
54
# File 'lib/mangdown/adapter.rb', line 53

def page_image_src
end

#typeObject



20
21
22
# File 'lib/mangdown/adapter.rb', line 20

def type
  self.class.to_s.split('::').last.downcase.to_sym
end