mangdown 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39eae36cb18260f996d55849997b0b28bd306985
4
- data.tar.gz: 1b097d36b0d567f0464ec06ac0913a5f8efded53
3
+ metadata.gz: 8d79f8b057221a2a242c3f84e7e7676da88750b0
4
+ data.tar.gz: dc22aa9359778ffb500d40750718d876582477cf
5
5
  SHA512:
6
- metadata.gz: bd8cfb84002fed92ae7eb6ddba6a6d6e0fc73d7873f43afee0ed06324ee6975eb1988eca03c331f96322771b1d2df9a56351fb53bc85966e029bc5489fd32fc9
7
- data.tar.gz: 89b574acbf8fa239f780307b9befbd73eb40481a7a44d637a50954c814f85cec2c14538a14254792ba392dfe7f3a2f2fa75cb670fc4e76ae1bdb75706669157f
6
+ metadata.gz: 261ea5c3270de92ae280a901ba8ea3c47c9b239db690b174a88d6aa41a6955ad579195e6087e48dfd1ba312df7965abca4354f2dea3fcbd71bc42f23a9ea7693
7
+ data.tar.gz: 672b6ae539b57a2ac4cd3183ac4a0aa7a66c76f46b50558ca55c481a66a3c1a971ed0bf06f27ef5ad9a23101e11816d870559900697450cb0e35d731a4d1c94b
@@ -1,6 +1,7 @@
1
1
  module Mangdown
2
2
  class Chapter
3
3
 
4
+ include Equality
4
5
  include Enumerable
5
6
  attr_reader :name, :uri, :pages, :manga, :chapter
6
7
 
@@ -10,7 +11,7 @@ module Mangdown
10
11
  ' ' + num.to_i.to_s.rjust(3, '0')
11
12
  }
12
13
  @manga = name.slice(/(^.+)\s/, 1)
13
- @chapter = name.slice(/\d+\z/)
14
+ @chapter = name.slice(/\d+\z/).to_i
14
15
  @uri = Mangdown::Uri.new(uri)
15
16
  @properties = Properties.new(@uri)
16
17
  @pages = []
@@ -37,7 +38,7 @@ module Mangdown
37
38
  threads = []
38
39
  each do |page|
39
40
  threads << Thread.new(page) do |this_page|
40
- Tools.no_time_out {this_page.download_to(dir)}
41
+ Tools.no_time_out {this_page.to_page.download_to(dir)}
41
42
  end
42
43
  end
43
44
 
@@ -95,8 +96,9 @@ module Mangdown
95
96
 
96
97
  MDHash.new(
97
98
  uri: image['src'],
98
- name: (image['alt'] + ".jpg")
99
- ).to_page
99
+ name: (image['alt'] + ".jpg"),
100
+ site: @properties.type,
101
+ )
100
102
  rescue NoMethodError => error
101
103
  puts 'doc was ' + doc.class
102
104
  end
@@ -124,8 +126,9 @@ module Mangdown
124
126
 
125
127
  MDHash.new(
126
128
  uri: image[:src],
127
- name: image[:src].sub(/.+\//, '')
128
- ).to_page
129
+ name: image[:src].sub(/.+\//, ''),
130
+ site: @properties.type,
131
+ )
129
132
  end
130
133
 
131
134
  # get the number of pages
@@ -32,40 +32,39 @@ module M
32
32
  end
33
33
 
34
34
  private
35
- # convenience method to access the data file path
36
- def path
37
- DATA_FILE_PATH
38
- end
39
-
40
- # check if the data file is current
41
- def file_current?(f)
42
- File.exists?(f) && File.mtime(f) > (Time.now - 604800)
43
- end
35
+ # convenience method to access the data file path
36
+ def path
37
+ DATA_FILE_PATH
38
+ end
44
39
 
45
- # attempt to get the list from the data file
46
- def data_from_file
47
- YAML.load(File.open(path, 'r').read) if file_current?(path)
48
- rescue Psych::SyntaxError => error
49
- error
50
- end
40
+ # check if the data file is current
41
+ def file_current?(f)
42
+ File.exists?(f) && File.mtime(f) > (Time.now - 604800)
43
+ end
51
44
 
45
+ # attempt to get the list from the data file
46
+ def data_from_file
47
+ YAML.load(File.read(path)) if file_current?(path)
48
+ end
52
49
 
53
- # get saved current manga list, if data is less than a week old
54
- # otherwise fetch new data and write it to the data file
55
- def current_manga_list
56
- data = data_from_file
57
- return data if data.is_a? Mangdown::MangaList
50
+ # get saved current manga list, if data is less than a week old
51
+ # otherwise fetch new data and write it to the data file
52
+ def current_manga_list
53
+ data = data_from_file
54
+ return MangaList.from_data(data) if data.is_a? Array
58
55
 
59
- MangaList.new(
60
- 'http://www.mangareader.net/alphabetical',
61
- 'http://mangafox.me/manga/'
62
- ).tap { |list| File.open(path,'w+') {|f| f.write(list.to_yaml)} }
63
- end
56
+ MangaList.new(
57
+ 'http://www.mangareader.net/alphabetical',
58
+ 'http://mangafox.me/manga/'
59
+ ).tap { |list| File.open(path,'w+') {|f| f.write(list.to_yaml)} }
60
+ rescue Object => error
61
+ puts "#{path} is corrupt: #{error.message}"
62
+ end
64
63
 
65
- # check if the search key contains letters or numbers
66
- def validate_search(search)
67
- unless search =~ /\w/
68
- raise ArgumentError, "Searches must contain letters and numbers"
69
- end
64
+ # check if the search key contains letters or numbers
65
+ def validate_search(search)
66
+ unless search =~ /\w/
67
+ raise ArgumentError, "Searches must contain letters and numbers"
70
68
  end
69
+ end
71
70
  end
@@ -5,69 +5,72 @@ module Mangdown
5
5
  # mangdown manga object, which holds chapters
6
6
  class Manga
7
7
 
8
+ include Equality
8
9
  include Enumerable
9
10
  attr_reader :name, :uri, :chapters, :enum
10
11
 
11
12
  def initialize(name, uri)
12
13
  @name = name
13
- @uri = uri
14
+ @uri = Mangdown::Uri.new(uri)
14
15
  @chapters = []
16
+ @properties = Properties.new(@uri)
15
17
 
16
18
  get_chapters
19
+ #@chapters.select! { |chapter| @properties.is_chapter?(chapter) }
17
20
  end
18
21
 
19
- public
20
- # download to current directory convenience method
21
- def download(*args)
22
- download_to(DOWNLOAD_DIR,*args)
23
- end
24
-
25
- # download using enumerable
26
- def download_to(dir, start = 0, stop = -1)
27
- dir += "/#{name}"
28
- reset(start, stop)
29
- Dir.mkdir(dir) unless Dir.exist?(dir)
30
- loop do
31
- self.next.to_chapter.download_to(dir)
32
- end
22
+ # download to current directory convenience method
23
+ def download(*args)
24
+ download_to(DOWNLOAD_DIR,*args)
25
+ end
26
+
27
+ # download using enumerable
28
+ def download_to(dir, start = 0, stop = -1)
29
+ dir += "/#{name}"
30
+ reset(start, stop)
31
+ Dir.mkdir(dir) unless Dir.exist?(dir)
32
+ loop do
33
+ self.next.to_chapter.download_to(dir)
33
34
  end
35
+ end
34
36
 
35
- # explicit conversion to manga
36
- def to_manga
37
- self
38
- end
37
+ # explicit conversion to manga
38
+ def to_manga
39
+ self
40
+ end
39
41
 
40
- # each for enumerating through chapters
41
- def each
42
- @chapters.each {|chapter| yield(chapter) if block_given?}
43
- end
42
+ # each for enumerating through chapters
43
+ def each
44
+ @chapters.each {|chapter| yield(chapter) if block_given?}
45
+ end
44
46
 
45
- # go through the chapters one at a time
46
- def next
47
- @enum || reset
48
- @enum.next
49
- end
47
+ # go through the chapters one at a time
48
+ def next
49
+ @enum || reset
50
+ @enum.next
51
+ end
50
52
 
51
- # reset enum for next
52
- def reset(start = 0, stop = -1)
53
- @enum = each[start..stop].lazy
54
- end
55
-
56
- # get push MDHashes of manga chapters to @chapters
57
- def get_chapters
58
- properties = Properties.new(@uri)
59
- doc = Tools.get_doc(@uri)
60
- root = properties.root
53
+ private
54
+ # reset enum for next
55
+ def reset(start = 0, stop = -1)
56
+ @enum = each[start..stop].lazy
57
+ end
61
58
 
62
- #get the link with chapter name and uri
63
- doc.css(properties.manga_css_klass).each do |chapter|
64
- @chapters << MDHash.new(
65
- uri: (root + chapter[:href].sub(root, '')),
66
- name: chapter.text,
67
- )
68
- end
59
+ # get push MDHashes of manga chapters to @chapters
60
+ def get_chapters
61
+ doc = Tools.get_doc(@uri)
62
+ root = @properties.root
69
63
 
70
- @chapters.reverse! if properties.reverse
64
+ #get the link with chapter name and uri
65
+ doc.css(@properties.manga_css_klass).each do |chapter|
66
+ @chapters << MDHash.new(
67
+ uri: (root + chapter[:href].sub(root, '')),
68
+ name: chapter.text,
69
+ site: @properties.type,
70
+ )
71
71
  end
72
+
73
+ @chapters.reverse! if @properties.reverse
74
+ end
72
75
  end
73
76
  end
@@ -5,10 +5,21 @@ module Mangdown
5
5
 
6
6
  attr_reader :mangas
7
7
 
8
- def initialize(*uri)
9
- @mangas = []
8
+ def self.from_data(mangas)
9
+ new(nil, mangas: mangas)
10
+ end
11
+
12
+ def initialize(*uri, mangas: [])
13
+ @mangas = mangas
14
+ if mangas.empty?
15
+ uri.each {|uri| get_mangas(uri)}
16
+ else
17
+ @mangas.map! { |hash| MDHash.new(hash) }
18
+ end
19
+ end
10
20
 
11
- uri.each {|uri| get_mangas(uri)}
21
+ def to_yaml
22
+ @mangas.map(&:to_hash).to_yaml
12
23
  end
13
24
 
14
25
  # get a list of mangas from the uri
@@ -1,14 +1,12 @@
1
1
  module Mangdown
2
-
3
- extend self
4
-
5
- def eql?(other)
6
- (self.name == other.name) and (self.uri == other.uri)
2
+ module Equality
3
+ def eql?(other)
4
+ (self.name == other.name) && (self.uri == other.uri)
5
+ end
6
+
7
+ def ==(other)
8
+ puts "You may want to use :eql?"
9
+ super
10
+ end
7
11
  end
8
-
9
- def ==(other)
10
- puts "You may want to use :eql?"
11
- super
12
- end
13
12
  end
14
-
@@ -1,34 +1,66 @@
1
1
  module Mangdown
2
- class MDHash < ::Hash
2
+ class MDHash
3
+ include Equality
4
+
5
+ attr_reader :properties
3
6
 
4
7
  def initialize(options = {})
5
- self[:uri] = options[:uri]
6
- self[:name] = options[:name]
8
+ @properties = Properties.new(options[:site] || options[:uri])
9
+
10
+ @hash = {}
11
+ [:uri, :name].each {|key| @hash[key] = options.fetch(key)}
12
+ @hash[:uri] = Mangdown::Uri.new(@hash[:uri])
13
+ @hash[:site] = @properties.type
7
14
  end
8
15
 
9
16
  # explicit conversion to manga
10
17
  def to_manga
11
- Manga.new(name, uri)
18
+ if @properties.is_manga?(self)
19
+ Manga.new(name, uri)
20
+ else
21
+ raise NoMethodError, 'This is not a known manga type'
22
+ end
12
23
  end
13
24
 
14
25
  # explicit conversion to chapter
15
26
  def to_chapter
16
- Properties.new(uri).chapter_klass.new(name, uri)
27
+ if @properties.is_chapter?(self)
28
+ @properties.chapter_klass.new(name, uri)
29
+ else
30
+ raise NoMethodError, 'This is not a known chapter type'
31
+ end
17
32
  end
18
33
 
19
34
  # explicit conversion to page
20
35
  def to_page
21
- Page.new(name, uri)
36
+ if @properties.is_page?(self)
37
+ Page.new(name, uri)
38
+ else
39
+ raise NoMethodError, 'This is not a known page type'
40
+ end
22
41
  end
23
42
 
24
43
  # name reader
25
44
  def name
26
- self[:name]
45
+ @hash[:name]
27
46
  end
28
47
 
29
48
  # uri reader
30
49
  def uri
31
- self[:uri]
50
+ @hash[:uri]
51
+ end
52
+
53
+ def [](key)
54
+ @hash[key]
55
+ end
56
+
57
+ def inspect
58
+ @hash
59
+ end
60
+ alias_method :to_hash, :inspect
61
+
62
+ def type
63
+ @properties.type
32
64
  end
33
65
  end
34
66
  end
data/lib/mangdown/page.rb CHANGED
@@ -1,13 +1,11 @@
1
1
  module Mangdown
2
2
  class Page
3
3
 
4
- include Mangdown
5
- include Comparable
6
-
4
+ include Equality
7
5
  attr_reader :name, :uri
8
6
 
9
7
  def initialize(name, uri)
10
- @name = name.sub(/(\s)(\d+)(\.\w+)$/) {
8
+ @name = name.sub(/([^\d])(\d+)(\.\w+)$/) {
11
9
  "#{Regexp.last_match[1]}" +
12
10
  "#{Regexp.last_match[2].to_s.rjust(3, '0')}" +
13
11
  "#{Regexp.last_match[3]}"
@@ -1,6 +1,7 @@
1
1
  module Mangdown
2
2
  class PopularManga
3
3
 
4
+ include Equality
4
5
  include Enumerable
5
6
  attr_reader :uri, :mangas, :name
6
7
 
@@ -19,6 +20,8 @@ module Mangdown
19
20
  end
20
21
 
21
22
  private
23
+ # I guess this is only for manga reader. need to use properties
24
+ # and or sub classes for other sites
22
25
  def get_mangas_list
23
26
  (@num_mangas / 30.0).ceil.times do |time|
24
27
  @mangas += get_pop_page_manga(time)
@@ -1,20 +1,23 @@
1
1
  module Mangdown
2
2
  class Properties
3
3
 
4
- attr_reader :info
4
+ attr_reader :info, :type
5
5
 
6
6
  def initialize(site)
7
7
  @info = Hash.new
8
8
 
9
- case site
9
+ case site.to_s
10
10
  when /mangareader/
11
+ @type = :mangareader
11
12
  mangareader
12
13
  when /mangapanda/
13
14
  #mangapanda is a mirror of mangareader
14
15
  #that being said, I really don't think this works
15
16
  #especially with @info[:root]
16
- mangareader
17
+ @type = :mangapanda
18
+ mangapanda
17
19
  when /mangafox/
20
+ @type = :mangafox
18
21
  mangafox
19
22
  else
20
23
  nil
@@ -25,11 +28,22 @@ module Mangdown
25
28
  @info[:manga_list_css_klass] = 'ul.series_alpha li a'
26
29
  @info[:manga_css_klass] = 'div#chapterlist td a'
27
30
  @info[:chapter_klass] = MRChapter
28
- @info[:root] = 'http://www.mangareader.net'
29
- @info[:manga_link_prefix] = @info[:root]
31
+ @info[:root] ||= 'http://www.mangareader.net'
32
+ @info[:manga_link_prefix] ||= @info[:root]
30
33
  @info[:reverse] = false
34
+ @info[:manga_uri_regex] =
35
+ /#{@info[:root]}(\/\d+)?(\/[^\/]+)(\.html)?/i
36
+ @info[:chapter_uri_regex] =
37
+ /#{@info[:root]}(\/[^\/]+){1,2}\/(\d+|chapter-\d+\.html)/i
38
+ @info[:page_uri_regex] = /.+\.(png|jpg|jpeg)$/i
31
39
  end
32
40
 
41
+ def mangapanda
42
+ @info[:root] = 'http://www.mangapanda.com'
43
+ @info[:manga_link_prefix] = @info[:root]
44
+ mangareader
45
+ end
46
+
33
47
  def mangafox
34
48
  @info[:manga_list_css_klass] = 'div.manga_list li a'
35
49
  @info[:manga_css_klass] = 'a.tips'
@@ -37,18 +51,37 @@ module Mangdown
37
51
  @info[:root] = 'http://mangafox.me'
38
52
  @info[:manga_link_prefix] = ''
39
53
  @info[:reverse] = true
54
+ @info[:manga_uri_regex] =
55
+ /#{@info[:root]}\/manga\/[^\/]+?\//i
56
+ @info[:chapter_uri_regex] = /
57
+ #{@info[:manga_uri_regex]}
58
+ (v\d+\/)?(c\d+\/)(1\.html)
59
+ /xi
60
+ @info[:page_uri_regex] = /.+\.(png|jpg|jpeg)$/i
40
61
  end
41
62
 
63
+ def is_manga?(obj)
64
+ obj.uri.slice(@info[:manga_uri_regex]) == obj.uri
65
+ end
66
+
67
+ def is_chapter?(obj)
68
+ obj.uri.slice(@info[:chapter_uri_regex]) == obj.uri
69
+ end
70
+
71
+ def is_page?(obj)
72
+ obj.uri.slice(@info[:page_uri_regex]) == obj.uri
73
+ end
74
+
42
75
  def empty?
43
76
  @info.empty?
44
77
  end
45
78
 
46
79
  private
47
- def method_missing(method, *args, &block)
48
- # this should probably be if @info.has_key?(method)
49
- # or more consisely @info.fetch(method) { super }
50
- return @info[method] unless @info[method].nil?
51
- super
52
- end
80
+ def method_missing(method, *args, &block)
81
+ # this should probably be if @info.has_key?(method)
82
+ # or more consisely @info.fetch(method) { super }
83
+ return @info[method] unless @info[method].nil?
84
+ super
85
+ end
53
86
  end
54
87
  end
@@ -3,6 +3,7 @@ require_relative '../../spec_helper'
3
3
  describe Mangdown::Chapter do
4
4
  let(:download_path) { File.expand_path('../../../../tmp', __FILE__) }
5
5
  let(:chapter_name) { "Dragon Ball 1" }
6
+ let(:download_chapter_name) { "Dragon Ball 001" }
6
7
  let(:uri) {
7
8
  "http://www.mangareader.net/105-2100-1/dragon-ball/chapter-1.html"
8
9
  }
@@ -37,7 +38,7 @@ describe Mangdown::Chapter do
37
38
  it 'must iterate through each page' do
38
39
  count = 0
39
40
  @chapter.each do |page|
40
- page.must_be_instance_of Mangdown::Page
41
+ page.to_page.must_be_instance_of Mangdown::Page
41
42
  count += 1
42
43
  end
43
44
  count.must_equal @chapter.pages.length
@@ -62,7 +63,7 @@ describe Mangdown::Chapter do
62
63
  end
63
64
 
64
65
  it 'must create a subdirectory with the chapter name' do
65
- Dir.exist?("#{download_path}/#{chapter_name}").must_equal true
66
+ Dir.exist?("#{download_path}/#{download_chapter_name}").must_equal true
66
67
  end
67
68
 
68
69
  it 'must have page files in the sub directory' do
@@ -0,0 +1,61 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Mangdown::Manga do
4
+ let(:download_path) { File.expand_path('../../../../tmp', __FILE__) }
5
+ let(:manga_name) { "Romance Dawn" }
6
+ let(:uri) {
7
+ "http://mangafox.me/manga/romance_dawn/"
8
+ }
9
+
10
+ before do
11
+ VCR.insert_cassette 'events', record: :new_episodes
12
+ @manga = Mangdown::Manga.new(manga_name, uri)
13
+ end
14
+
15
+ after do
16
+ VCR.eject_cassette
17
+ FileUtils.rm_r("#{download_path}/#{manga_name}", force: true)
18
+ end
19
+
20
+ describe 'new' do
21
+ it 'must return a manga' do
22
+ @manga.must_be_instance_of Mangdown::Manga
23
+ end
24
+
25
+ it 'must have chapters' do
26
+ @manga.chapters.wont_be :empty?
27
+ end
28
+ end
29
+
30
+ describe 'download' do
31
+ it 'must download to default download dir' do
32
+ @manga.download
33
+
34
+ dir = Mangdown::DOWNLOAD_DIR + "/#{manga_name}"
35
+ Dir.exist?(dir).must_equal true
36
+ end
37
+
38
+ it 'must download to the given dir' do
39
+ dir = Mangdown::DOWNLOAD_DIR + '/random'
40
+ FileUtils.rm_r(dir, force: true) if Dir.exist?(dir)
41
+
42
+ Dir.mkdir(dir)
43
+ @manga.download_to(dir)
44
+
45
+ Dir.exist?(dir + "/#{manga_name}").must_equal true
46
+
47
+ FileUtils.rm_r(dir, force: true)
48
+ end
49
+
50
+ it 'must download the right number of chapters' do
51
+ manga = Mangdown::Manga
52
+ .new('Gantz', 'http://www.mangareader.net/97/gantz.html')
53
+ manga.download(50, 52)
54
+
55
+ chapters = Dir[Mangdown::DOWNLOAD_DIR + '/Gantz/*/']
56
+ chapters.length.must_equal 3
57
+
58
+ FileUtils.rm_r(Mangdown::DOWNLOAD_DIR + '/Gantz', force: true)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Mangdown::Manga do
4
+ let(:m_name) { "Romance Dawn" }
5
+ let(:m_uri) { "http://mangafox.me/manga/romance_dawn/" }
6
+
7
+ let(:c_name) { "Onepunch-Man 1" }
8
+ let(:c_uri) { "http://www.mangareader.net/onepunch-man/1" }
9
+
10
+ let(:c2_name) { "Naruto 542" }
11
+ let(:c2_uri) { "http://mangafox.me/manga/naruto/v57/c542/1.html" }
12
+
13
+ let(:p_name) { "Hikaru No Go 1 - Page 1.jpg" }
14
+ let(:p_uri) {
15
+ "http://i1.mangareader.net/hikaru-no-go/1/hikaru-no-go-1894067.jpg"
16
+ }
17
+
18
+ before do
19
+ VCR.insert_cassette 'events', record: :new_episodes
20
+ @md_page = Mangdown::MDHash.new(uri: p_uri, name: p_name)
21
+ @md_chapter = Mangdown::MDHash.new(uri: c_uri, name: c_name)
22
+ @md_manga = Mangdown::MDHash.new(uri: m_uri, name: m_name)
23
+ end
24
+
25
+ after do
26
+ VCR.eject_cassette
27
+ end
28
+
29
+ describe 'new' do
30
+ it 'must return a manga' do
31
+ [@md_page, @md_chapter, @md_manga].each do |type|
32
+ type.must_be_instance_of Mangdown::MDHash
33
+ end
34
+ end
35
+ end
36
+
37
+ describe 'to_manga' do
38
+ it 'must give a manga for a manga' do
39
+ @md_manga.to_manga.must_be_instance_of Mangdown::Manga
40
+ end
41
+
42
+ it 'must raise an exception if not a manga' do
43
+ [@md_chapter, @md_page].each do |type|
44
+ Proc.new { type.to_manga }.must_raise NoMethodError
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'to_chapter' do
50
+ it 'must give a manga read chapter for a manga reader chapter' do
51
+ @md_chapter.to_chapter.must_be_instance_of Mangdown::MRChapter
52
+ end
53
+
54
+ it 'must give a manga fox chapter for a manga fox chapter' do
55
+ md = Mangdown::MDHash.new(uri: c2_uri, name: c2_name)
56
+ md.to_chapter.must_be_instance_of Mangdown::MFChapter
57
+ end
58
+
59
+ it 'must raise an exception if not a chapter' do
60
+ [@md_page, @md_manga].each do |type|
61
+ Proc.new { type.to_chapter }.must_raise NoMethodError
62
+ end
63
+ end
64
+ end
65
+
66
+ describe 'to_page' do
67
+ it 'must give a page for a page' do
68
+ @md_page.to_page.must_be_instance_of Mangdown::Page
69
+ end
70
+
71
+ it 'must raise an exception if not a page' do
72
+ [@md_chapter, @md_manga].each do |type|
73
+ Proc.new { type.to_page }.must_raise NoMethodError
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../../spec_helper.rb'
2
+
3
+ describe Mangdown do
4
+ before do
5
+ VCR.insert_cassette 'events', record: :new_episodes
6
+ end
7
+
8
+ after do
9
+ VCR.eject_cassette
10
+ end
11
+
12
+ describe 'eql?' do
13
+ it 'should return true when two objects are symatically equal' do
14
+ monster1 = M.find('monster').first
15
+ monster2 = M.find('monster').first
16
+ (monster1 == monster2).must_equal(false)
17
+ (monster1.eql?(monster2)).must_equal(true)
18
+ end
19
+
20
+ it 'should return true when two objects are symantically unequal' do
21
+ monster1 = M.find('monster').first
22
+ monster2 = M.find('20th century boys').first
23
+ (monster1 == monster2).must_equal(false)
24
+ (monster1.eql?(monster2)).must_equal(false)
25
+ end
26
+
27
+ it 'should return true even if different classes' do
28
+ monster1 = M.find('monster').first
29
+ monster2 = monster1.to_manga
30
+ (monster1 == monster2).must_equal(false)
31
+ (monster1.eql?(monster2)).must_equal(true)
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,38 @@
1
+ require_relative '../../spec_helper.rb'
2
+
3
+ describe Mangdown::Page do
4
+ before do
5
+ VCR.insert_cassette 'events', record: :new_episodes
6
+ end
7
+
8
+ after do
9
+ VCR.eject_cassette
10
+ end
11
+
12
+ describe 'new' do
13
+ let(:mangareader) {
14
+ Mangdown::Page.new(
15
+ "Naruto 1 - Page 1.jpg",
16
+ "http://i19.mangareader.net/naruto/1/naruto-1564773.jpg"
17
+ )
18
+ }
19
+ let(:mangafox) {
20
+ Mangdown::Page.new(
21
+ "i001.jpg",
22
+ "http://a.mfcdn.net/store/manga/10807/000.0/compressed/i001.jpg"
23
+ )
24
+ }
25
+ let(:mangafox2) {
26
+ Mangdown::Page.new(
27
+ "naruto_pilot_manga.naruto_pilot_01.jpg",
28
+ "http://a.mfcdn.net/store/manga/8/01-000.0/compressed/naruto_pilot_manga.naruto_pilot_01.jpg"
29
+ )
30
+ }
31
+
32
+ it 'have a valid name' do
33
+ [mangareader, mangafox, mangafox2].each do |type|
34
+ type.name.must_match(/\d{3}\.jpg$/)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Mangdown::PopularManga do
4
+ let(:mangareader) {
5
+ Mangdown::PopularManga.new('http://www.mangareader.net/popular')
6
+ }
7
+
8
+ before do
9
+ VCR.insert_cassette 'events', record: :new_episodes
10
+ end
11
+
12
+ after do
13
+ VCR.eject_cassette
14
+ end
15
+
16
+ describe 'new' do
17
+ it 'must have a list of mangas' do
18
+ mangareader.mangas.wont_be(:empty?)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Mangdown::Properties do
4
+ let(:mangareader) {
5
+ Mangdown::Properties.new('http://www.mangareader.net/101/akira.html')
6
+ }
7
+ let(:mangafox) {
8
+ Mangdown::Properties.new('"http://mangafox.me/manga/ashita_no_joe/')
9
+ }
10
+ let(:mangapanda) {
11
+ Mangdown::Properties.new('http://www.mangapanda.com/fairy-tail/424')
12
+ }
13
+
14
+ describe 'new' do
15
+ it 'must give the right info' do
16
+ mangareader.type.must_equal(:mangareader)
17
+ mangapanda.type.must_equal( :mangapanda)
18
+ mangafox.type.must_equal( :mangafox)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Mangdown::Tools do
4
+ let(:m_uri) { "http://mangafox.me/manga/romance_dawn/" }
5
+
6
+ let(:c_uri) { "http://www.mangareader.net/onepunch-man/1" }
7
+
8
+ let(:c2_uri) { "http://mangafox.me/manga/naruto/v57/c542/1.html" }
9
+
10
+ let(:p_uri) {
11
+ "http://i1.mangareader.net/hikaru-no-go/1/hikaru-no-go-1894067.jpg"
12
+ }
13
+
14
+ before do
15
+ VCR.insert_cassette 'events', record: :new_episodes
16
+ end
17
+
18
+ after do
19
+ VCR.eject_cassette
20
+ end
21
+
22
+ describe 'get_doc' do
23
+ it 'must return a Nokogiri Document' do
24
+ Mangdown::Tools.get_doc(m_uri)
25
+ .must_be_instance_of(Nokogiri::HTML::Document)
26
+ end
27
+ end
28
+
29
+ describe 'get_root' do
30
+ it 'must return the protocol and host of the uri' do
31
+ Mangdown::Tools.get_root(m_uri)
32
+ .must_equal('http://mangafox.me')
33
+ Mangdown::Tools.get_root(c_uri)
34
+ .must_equal('http://www.mangareader.net')
35
+ Mangdown::Tools.get_root(c2_uri)
36
+ .must_equal('http://mangafox.me')
37
+ Mangdown::Tools.get_root(p_uri)
38
+ .must_equal('http://i1.mangareader.net')
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Mangdown::Uri do
4
+ let(:m_uri) { "http://mangafox.me/manga/romance_dawn/" }
5
+
6
+ let(:c_uri) { "http://www.mangareader.net/onepunch-man/1" }
7
+
8
+ let(:c2_uri) { "http://mangafox.me/manga/naruto/v57/c542/1.html" }
9
+
10
+ let(:p_uri) {
11
+ "http://i1.mangareader.net/hikaru-no-go/1/hikaru-no-go-1894067.jpg"
12
+ }
13
+
14
+ describe 'get_doc' do
15
+ it 'must return a String object' do
16
+ Mangdown::Uri.new(m_uri).must_be_instance_of(String)
17
+ end
18
+
19
+ it 'must return a properly encoded uri' do
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jphager2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -198,6 +198,14 @@ files:
198
198
  - spec/lib/mangdown/chapter_spec.rb
199
199
  - spec/lib/mangdown/commands_spec.rb
200
200
  - spec/lib/mangdown/manga_list_spec.rb
201
+ - spec/lib/mangdown/manga_spec.rb
202
+ - spec/lib/mangdown/mangdown_hash_spec.rb
203
+ - spec/lib/mangdown/mangdown_spec.rb
204
+ - spec/lib/mangdown/page_spec.rb
205
+ - spec/lib/mangdown/popular_spec.rb
206
+ - spec/lib/mangdown/properties_spec.rb
207
+ - spec/lib/mangdown/tools_spec.rb
208
+ - spec/lib/mangdown/uri_spec.rb
201
209
  - spec/mangdown/chapter_spec.rb
202
210
  - spec/mangdown/commands_spec.rb
203
211
  - spec/mangdown/manga_list_spec.rb
@@ -230,5 +238,5 @@ rubyforge_project:
230
238
  rubygems_version: 2.2.2
231
239
  signing_key:
232
240
  specification_version: 4
233
- summary: Downloads Manga, 0.9.0 has some big API changes
241
+ summary: Downloads Manga, 0.10.0 has some big API changes
234
242
  test_files: []