cdb-crawlr 0.2.0 → 0.2.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.
- data/bin/cdb +27 -6
- data/lib/cdb-crawlr.rb +1 -1
- data/lib/cdb/cli.rb +18 -6
- data/lib/cdb/series.rb +1 -1
- data/lib/cdb/struct.rb +9 -3
- metadata +4 -4
data/bin/cdb
CHANGED
@@ -7,27 +7,48 @@ require 'optparse'
|
|
7
7
|
$cli = CDB::CLI.new
|
8
8
|
|
9
9
|
def print_help(opt = @global, error=nil)
|
10
|
-
puts
|
10
|
+
puts(error.to_s+"\n\n") if error
|
11
11
|
puts opt
|
12
12
|
exit 1
|
13
13
|
end
|
14
14
|
|
15
15
|
@global = OptionParser.new do |opts|
|
16
|
-
opts.banner = "Usage: cdb [-h|--help] [-v|--version] <
|
16
|
+
opts.banner = "Usage: cdb [-h|--help] [-v|--version] <COMMAND> <TYPE> [<ARGS>]"
|
17
|
+
|
17
18
|
opts.on("-h", "--help", "Display this screen"){ print_help }
|
18
19
|
opts.on("-v", "--version", "Show version information") do
|
19
20
|
puts "cdb #{CDB::VERSION}"; exit
|
20
21
|
end
|
22
|
+
|
23
|
+
opts.separator "\nCOMMANDS:"
|
24
|
+
opts.separator " search Search for entries of a given TYPE matching QUERY"
|
25
|
+
opts.separator " show Show details of an entry using a CDB_ID obtained from search"
|
21
26
|
end
|
22
27
|
|
23
28
|
@search = OptionParser.new do |opts|
|
24
|
-
opts.banner = "
|
29
|
+
opts.banner = "Search for entries of a given TYPE matching QUERY\n"+
|
30
|
+
"Usage: cdb search [-h|--help] <TYPE> <QUERY>"
|
31
|
+
|
25
32
|
opts.on("-h", "--help", "Display this screen"){ print_help opts }
|
33
|
+
|
34
|
+
opts.separator "\nTYPES:"
|
35
|
+
opts.separator " issue Search comic issue names for given QUERY"
|
36
|
+
opts.separator " series Search comic series names for given QUERY"
|
37
|
+
end
|
38
|
+
|
39
|
+
@show = OptionParser.new do |opts|
|
40
|
+
opts.banner = "Show details of an entry using a CDB_ID obtained from search\n"+
|
41
|
+
"Usage: cdb show [-h|--help] <TYPE> <CDB_ID>"
|
42
|
+
|
43
|
+
opts.on("-h", "--help", "Display this screen"){ print_help opts }
|
44
|
+
|
45
|
+
opts.separator "\nTYPES:"
|
46
|
+
opts.separator " series Get all available details of a comic series"
|
26
47
|
end
|
27
48
|
|
28
49
|
@command_opts = {
|
29
50
|
'search' => @search,
|
30
|
-
'show' =>
|
51
|
+
'show' => @show
|
31
52
|
}
|
32
53
|
|
33
54
|
# Parse global flags
|
@@ -43,7 +64,7 @@ begin
|
|
43
64
|
$cli[:command] = command
|
44
65
|
command_opt = @command_opts[$cli[:command]]
|
45
66
|
rescue
|
46
|
-
error = "
|
67
|
+
error = "invalid COMMAND: #{command}" unless command.to_s.empty?
|
47
68
|
print_help @global, error
|
48
69
|
end
|
49
70
|
|
@@ -59,7 +80,7 @@ begin
|
|
59
80
|
type = ARGV.shift
|
60
81
|
$cli[:type] = type
|
61
82
|
rescue
|
62
|
-
error = "invalid
|
83
|
+
error = "invalid TYPE: #{type}" unless type.to_s.empty?
|
63
84
|
print_help command_opt, error
|
64
85
|
end
|
65
86
|
|
data/lib/cdb-crawlr.rb
CHANGED
data/lib/cdb/cli.rb
CHANGED
@@ -2,7 +2,7 @@ require 'pp'
|
|
2
2
|
|
3
3
|
module CDB
|
4
4
|
class CLI
|
5
|
-
COMMANDS = %w[search]
|
5
|
+
COMMANDS = %w[search show]
|
6
6
|
TYPES = %w[series issue issues]
|
7
7
|
|
8
8
|
def initialize(options={})
|
@@ -20,12 +20,15 @@ module CDB
|
|
20
20
|
v = v.downcase
|
21
21
|
raise unless COMMANDS.include?(v)
|
22
22
|
when :type
|
23
|
-
v = v.downcase
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
v = v.downcase
|
24
|
+
if self[:command] == 'show'
|
25
|
+
# remove when "show issue" is supported
|
26
|
+
raise unless v == 'series'
|
27
|
+
else
|
28
|
+
raise unless TYPES.include?(v)
|
28
29
|
end
|
30
|
+
when :args
|
31
|
+
raise "invalid args" if v.empty?
|
29
32
|
end
|
30
33
|
@options[k] = v
|
31
34
|
end
|
@@ -45,5 +48,14 @@ module CDB
|
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
51
|
+
def show
|
52
|
+
case self[:type]
|
53
|
+
when 'series'
|
54
|
+
res = CDB::Series.show(self[:args])
|
55
|
+
res.issues.each{|i| i.series=nil}
|
56
|
+
puts res.to_json(array_nl:"\n", object_nl:"\n", indent:' ')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
48
60
|
end
|
49
61
|
end
|
data/lib/cdb/series.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module CDB
|
2
|
-
class Series < Struct.new(:cdb_id, :name, :
|
2
|
+
class Series < Struct.new(:cdb_id, :name, :publisher, :imprint, :start_date, :end_date, :issues, :country, :language)
|
3
3
|
FORM_SEARCHTYPE = 'Title'
|
4
4
|
WEB_PATH = 'title.php'
|
5
5
|
|
data/lib/cdb/struct.rb
CHANGED
@@ -9,13 +9,19 @@ module CDB
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def as_json(*)
|
12
|
-
members.
|
12
|
+
members.each_with_object({}){|m, map|
|
13
13
|
next map unless self[m]
|
14
|
-
|
14
|
+
case self[m]
|
15
|
+
when Array
|
16
|
+
map[m] = self[m].collect(&:as_json)
|
17
|
+
else
|
18
|
+
map[m] = self[m]
|
19
|
+
end
|
15
20
|
}
|
16
21
|
end
|
17
22
|
|
18
|
-
def to_json(opts={})
|
23
|
+
def to_json(opts={}, depth=0)
|
24
|
+
opts = opts.to_h rescue opts
|
19
25
|
opts = {space:' ', object_nl:' '}.merge(opts)
|
20
26
|
self.as_json.to_json(opts)
|
21
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdb-crawlr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-04 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &25288420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *25288420
|
25
25
|
description: cdb-crawlr is a Ruby gem and command-line tool for querying ComicBookDB.com
|
26
26
|
email:
|
27
27
|
- sgt.floydpepper@gmail.com
|