mangdown 0.13.2 → 0.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4619032c750ec3a18f5427f6d51ed5d0ea934b20
4
- data.tar.gz: defdc99d480348dd4e17f72eec385596224d5df1
3
+ metadata.gz: 5b4edce6f4511a5513de3fc39acbee0bbadeb6a7
4
+ data.tar.gz: 10f48a8789a42a744029aa07812a6d506d0388ae
5
5
  SHA512:
6
- metadata.gz: 5dc4f1d2436738e29f96f729e85248c2e4d87d46c308cca0a31c245971b9439e9455f8fc9b04cbf9572637647c7d560e9836215f61e93078958f467a051e15e7
7
- data.tar.gz: f280db306b9dd05717a644b2b66dc19b5c28d255b67af05fae7003c928d89406c92d9f8c1a6f312e474875b1c19e85703a8e4ec496f6dda96316f015532ca4d4
6
+ metadata.gz: 1af096493c7ea75518ec6e7ddfd8c802d9f8af70744828b6573269f7dfcc0e2d990dc3fffa3780773cab1b79622ab49442dd1b236622e2614efc6c6d26cbea9c
7
+ data.tar.gz: 2dacfd63034bb0f519e7cc414573e363d3337f3fa1259ad1e7d3648173541af4c91df9acefa090ec8d80b68817f1daa251d3c81bdd746dd33164b0b221f460c1
@@ -26,6 +26,6 @@ require_relative 'mangdown/manga'
26
26
  require_relative 'mangdown/manga_list.rb'
27
27
  require_relative 'mangdown/cbz'
28
28
  require_relative 'mangdown/commands'
29
- require_relative 'mangdown/mangdown_hash'
29
+ require_relative 'mangdown/md_hash'
30
30
 
31
31
 
@@ -62,12 +62,17 @@ module Mangdown
62
62
  end
63
63
 
64
64
  # download all pages in a chapter
65
- def download_to(dir = nil)
65
+ def download_to(dir = nil, opts = { force_download: false })
66
66
  pages = map(&:to_page)
67
67
  failed = []
68
68
  succeeded = []
69
+ skipped = []
69
70
 
70
71
  setup_download_dir!(dir)
72
+ if opts[:force_download]
73
+ FileUtils.rm_r(to_path)
74
+ setup_download_dir!(dir)
75
+ end
71
76
 
72
77
  Tools.hydra_streaming(pages) do |stage, page, data = nil|
73
78
  case stage
@@ -76,7 +81,7 @@ module Mangdown
76
81
  when :succeeded
77
82
  succeeded << page
78
83
  when :before
79
- !page.file_exist?(to_path)
84
+ !(page.file_exist?(to_path) && skipped << page)
80
85
  when :body
81
86
  page.append_file_data(to_path, data) unless failed.include?(page)
82
87
  when :complete
@@ -84,9 +89,9 @@ module Mangdown
84
89
  end
85
90
  end
86
91
 
87
- FileUtils.rm_r(to_path) if succeeded.empty?
92
+ FileUtils.rm_r(to_path) if succeeded.empty? && skipped.empty?
88
93
 
89
- { failed: failed, succeeded: succeeded }
94
+ { failed: failed, succeeded: succeeded, skipped: skipped }
90
95
  end
91
96
 
92
97
  private
@@ -39,7 +39,7 @@ module Mangdown
39
39
  end
40
40
 
41
41
  # download using enumerable
42
- def download_to(dir, start = 0, stop = -1)
42
+ def download_to(dir, start = 0, stop = -1, opts = { force_download: false })
43
43
  start, stop = validate_indeces!(start, stop)
44
44
  setup_download_dir!(dir)
45
45
 
@@ -47,7 +47,7 @@ module Mangdown
47
47
  chapters[start..stop].each do |md_hash|
48
48
  chapter = md_hash.to_chapter
49
49
 
50
- if chapter.download_to(to_path)
50
+ if chapter.download_to(to_path, opts)
51
51
  bar.increment!
52
52
  else
53
53
  STDERR.puts("error: #{chapter.name} was not downloaded")
@@ -26,16 +26,18 @@ module Mangdown
26
26
  dir = Tools.valid_path_name(dir)
27
27
  path = File.join(dir, name)
28
28
  if Dir.exist?(dir)
29
- @path = Dir.entries(dir).find { |file| file.to_s[path] }
29
+ path = Dir.entries(dir).find { |file| file.to_s[path] } || path
30
30
  end
31
- @path ||= path
32
- @path = Tools.valid_path_name(@path)
33
- @path = Tools.relative_or_absolute_path(@path)
31
+ path = Tools.valid_path_name(path)
32
+ @path = Tools.relative_or_absolute_path(path)
34
33
  end
35
34
 
36
35
  # downloads to specified directory
37
- def download_to(dir = Dir.pwd)
38
- return if file_exist?(dir)
36
+ def download_to(dir = Dir.pwd, opts = { force_download: false })
37
+ return if file_exist?(dir) && !opts[:force_download]
38
+
39
+ # cleanup existing file (all extensions)
40
+ delete_files!(dir) if opts[:force_download]
39
41
 
40
42
  image = Tools.get(uri)
41
43
 
@@ -46,8 +48,6 @@ module Mangdown
46
48
  end
47
49
 
48
50
  def append_file_data(dir, data)
49
- set_path(dir)
50
-
51
51
  File.open(to_path, 'ab') { |file| file.write(data) }
52
52
  end
53
53
 
@@ -63,7 +63,13 @@ module Mangdown
63
63
  def file_exist?(dir = nil)
64
64
  set_path(dir) if dir
65
65
 
66
- Dir.entries(dir).any? { |file| file.to_s[to_path.to_s] }
66
+ Dir.entries(dir).any? { |file| file.to_s[to_path.basename.to_s] }
67
+ end
68
+
69
+ def delete_files!(dir)
70
+ while set_path(dir) && File.exist?(to_path)
71
+ File.delete(to_path)
72
+ end
67
73
  end
68
74
  end
69
75
  end
@@ -1,3 +1,3 @@
1
1
  module Mangdown
2
- VERSION = "0.13.2"
2
+ VERSION = "0.13.3"
3
3
  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.13.2
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jphager2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-10 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -158,7 +158,7 @@ files:
158
158
  - lib/mangdown/equality.rb
159
159
  - lib/mangdown/manga.rb
160
160
  - lib/mangdown/manga_list.rb
161
- - lib/mangdown/mangdown_hash.rb
161
+ - lib/mangdown/md_hash.rb
162
162
  - lib/mangdown/page.rb
163
163
  - lib/mangdown/properties.rb
164
164
  - lib/mangdown/tools.rb
@@ -172,7 +172,6 @@ files:
172
172
  - spec/lib/mangdown/manga_spec.rb
173
173
  - spec/lib/mangdown/mangdown_hash_spec.rb
174
174
  - spec/lib/mangdown/page_spec.rb
175
- - spec/lib/mangdown/popular_spec.rb
176
175
  - spec/lib/mangdown/properties_spec.rb
177
176
  - spec/lib/mangdown/tools_spec.rb
178
177
  - spec/lib/mangdown/uri_spec.rb
@@ -1,21 +0,0 @@
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