mangdown 0.16.0 → 0.16.1
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 +4 -4
- data/lib/mangdown/client.rb +51 -50
- data/lib/mangdown/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 322812e01eff29a30192673634873fcd286770c3
|
|
4
|
+
data.tar.gz: 97d4cc14476ec3a43d0ba11af6e9c541b65f3d63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8697dd6bd034b1634494ae62dae674271d8864cdefb2b905c3dd7ffc901a604bb3e5593c90a0a2a1ce4fcc5e2e2bb3c66f042a555d8a249c84bba5d6fdd927e4
|
|
7
|
+
data.tar.gz: bd1051ea8ea0e0974157b48d4f249fdc37fc34dfa9137ce0531be7d003ddd4dc0036bfa81683e25565e1427730c5b207c9c3de25f7a0ea1a20e3352d7c8f7191
|
data/lib/mangdown/client.rb
CHANGED
|
@@ -4,69 +4,70 @@ require_relative '../mangdown'
|
|
|
4
4
|
|
|
5
5
|
# Simple client for Mangdown
|
|
6
6
|
module M
|
|
7
|
-
|
|
7
|
+
class << self
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
DATA_FILE_PATH = Dir.home + '/.manga_list.yml'
|
|
10
|
+
HELP_FILE_PATH = File.expand_path(
|
|
11
|
+
'../../README.md', File.dirname(__FILE__)
|
|
12
|
+
)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
MANGA_PAGES = ['http://www.mangareader.net/alphabetical'].freeze
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
# return a list of hash with :uri and :name of mangas found in list
|
|
17
|
+
def find(search)
|
|
18
|
+
search = Regexp.new(/^#{search}$/) if search.respond_to?(:to_str)
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
current_manga_list.select { |manga| manga[:name] =~ search }
|
|
21
|
+
end
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
# cbz all subdirectories in a directory
|
|
24
|
+
def cbz(dir)
|
|
25
|
+
Mangdown::CBZ.all(dir)
|
|
26
|
+
rescue => error
|
|
27
|
+
raise Mangdown::Error, "Failed to package #{dir}: #{error.message}"
|
|
28
|
+
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
# display help file
|
|
31
|
+
def help
|
|
32
|
+
puts File.read(HELP_FILE_PATH)
|
|
33
|
+
end
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
# delete data file
|
|
36
|
+
def clean_up
|
|
37
|
+
File.delete(DATA_FILE_PATH) if File.exist?(DATA_FILE_PATH)
|
|
38
|
+
end
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
private
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
# convenience method to access the data file path
|
|
43
|
+
def path
|
|
44
|
+
DATA_FILE_PATH
|
|
45
|
+
end
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
# check if the data file is current
|
|
48
|
+
def file_current?(f)
|
|
49
|
+
File.exist?(f) && File.mtime(f) > (Time.now - 604_800)
|
|
50
|
+
end
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
# attempt to get the list from the data file
|
|
53
|
+
def data_from_file
|
|
54
|
+
YAML.safe_load(File.read(path)) if file_current?(path)
|
|
55
|
+
end
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
# get saved current manga list, if data is less than a week old
|
|
58
|
+
# otherwise fetch new data and write it to the data file
|
|
59
|
+
def current_manga_list
|
|
60
|
+
data = data_from_file
|
|
61
|
+
return Mangdown::MangaList.from_data(data) if data
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
list = MANGA_PAGES.inject([]) do |manga, uri|
|
|
64
|
+
list = Mangdown::MDHash.new(uri: uri).to_manga_list
|
|
65
|
+
list.merge(manga)
|
|
66
|
+
end
|
|
67
|
+
File.open(path, 'w+') { |f| f.write(list.to_yaml) }
|
|
68
|
+
list
|
|
69
|
+
rescue => error
|
|
70
|
+
raise Mangdown::Error, "#{path} may be corrupt: #{error.message}"
|
|
66
71
|
end
|
|
67
|
-
File.open(path, 'w+') { |f| f.write(list.to_yaml) }
|
|
68
|
-
list
|
|
69
|
-
rescue => error
|
|
70
|
-
raise Mangdown::Error, "#{path} may be corrupt: #{error.message}"
|
|
71
72
|
end
|
|
72
73
|
end
|
data/lib/mangdown/version.rb
CHANGED