bookscan 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bookscan}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoshihiro TAKAHARA"]
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.homepage = %q{http://github.com/tumf/bookscan}
41
41
  s.licenses = ["MIT"]
42
42
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.7}
43
+ s.rubygems_version = %q{1.4.2}
44
44
  s.summary = %q{BookScan Scraper}
45
45
  s.test_files = [
46
46
  "test/helper.rb",
@@ -48,7 +48,6 @@ Gem::Specification.new do |s|
48
48
  ]
49
49
 
50
50
  if s.respond_to? :specification_version then
51
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
51
  s.specification_version = 3
53
52
 
54
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -32,6 +32,7 @@ module Bookscan
32
32
  each do |b|
33
33
  return b if b.book_id == book_id
34
34
  end
35
+ nil
35
36
  end
36
37
 
37
38
  def has?(book_id)
@@ -19,7 +19,14 @@ module Bookscan
19
19
  transaction do |ps|
20
20
  ts = ps["tuned"]
21
21
  end
22
- ts
22
+ ts_uniq = Books.new
23
+ ts.each { |t|
24
+ unless ts_uniq.find { |i| i.title == t.title }
25
+ ts_uniq << t
26
+ end
27
+ }
28
+ require 'pp'
29
+ return ts_uniq.compact
23
30
  end
24
31
 
25
32
  def tuned?(book,type)
@@ -34,9 +41,9 @@ module Bookscan
34
41
  else
35
42
  bs = Books.new
36
43
  groups.each do |g|
37
- bs += g.books
44
+ g.books.each { |b| bs << b }
38
45
  end
39
- bs
46
+ return bs
40
47
  end
41
48
  end
42
49
 
@@ -109,70 +109,13 @@ module Bookscan
109
109
  hash = v
110
110
  end
111
111
  opt.parse!(@command_options)
112
-
113
- unless hash
114
- puts gs.to_s
115
- hash = ask('Enter hash: ',gs.hashes) do |q|
116
- q.validate = /\w+/
117
- q.readline = true
118
- end
119
- end
120
-
121
- g = gs.by_hash(hash)
122
- puts g.books.to_s
123
- end
124
-
125
- def ask_tuned_book_id(book_id,type)
126
- unless type
127
- type = ask('Enter tune type: ',TUNE_TYPES) do |q|
128
- q.validate = /\w+/
129
- q.readline = true
130
- end
131
- end
132
- ts = @cache.tuned
133
- ts.collect! do |i|
134
- i if i.tune_type == type
135
- end.compact!
136
- raise "No tuned in cache. Exceute 'bookscan update' first." unless ts.length > 0
137
- unless book_id
138
- puts ts.to_s
139
- book_id = ask('Enter book id: ',ts.ids) do |q|
140
- q.validate = /\w+/
141
- q.readline = true
142
- end
143
- end
144
- ts.by_id(book_id)
145
- end
146
-
147
- def ask_book_id(book_id,hash)
148
- gs = @cache.groups
149
- unless book_id
150
- unless hash
151
- puts gs.to_s
152
- hash = ask('Enter hash: ',gs.hashes) do |q|
153
- q.validate = /\w+/
154
- q.readline = true
155
- end
156
- g = gs.by_hash(hash)
157
-
158
- puts g.books.to_s
159
-
160
- book_id = ask('Enter book id: ',g.books.ids) do |q|
161
- q.validate = /\w+/
162
- q.readline = true
163
- end
164
-
165
- end
166
- end
167
- gs.book(book_id)
112
+ puts ask_group(hash,gs).books.to_s
168
113
  end
169
114
 
170
115
  def download
171
116
  opt = OptionParser.new
172
117
  directory = "."
173
- hash = nil
174
- type = nil
175
- dry_run = false
118
+ hash = nil;type = nil;pattern = ".*"; dry_run = false
176
119
  opt.on('-d DIR','--directory=DIR', 'download directory') do |v|
177
120
  directory = v
178
121
  end
@@ -182,6 +125,9 @@ module Bookscan
182
125
  opt.on('-t TYPE','--tuned=TYPE', 'download tuned') do |v|
183
126
  type = v
184
127
  end
128
+ opt.on('-m PATTERN','--match=PATTERN','pattern match') do |v|
129
+ pattern = v
130
+ end
185
131
  opt.on('--dry-run', 'dry-run mode') do |v|
186
132
  dry_run = true
187
133
  end
@@ -190,9 +136,13 @@ module Bookscan
190
136
 
191
137
  if book_id == "all"
192
138
  if type
193
- bs = @cache.tuned
139
+ bs = @cache.tuned.select { |i|
140
+ /#{pattern}/ =~ i.title
141
+ }
194
142
  else
195
- bs = @cache.books
143
+ bs = @cache.books.select { |i|
144
+ /#{pattern}/ =~ i.title
145
+ }
196
146
  end
197
147
  bs.each { |book|
198
148
  next unless book.tune_type == type
@@ -207,9 +157,9 @@ module Bookscan
207
157
  }
208
158
  else
209
159
  if type
210
- book = ask_tuned_book_id(book_id,type)
160
+ book = ask_tuned_book_id(book_id,type,pattern)
211
161
  else
212
- book = ask_book_id(book_id,hash)
162
+ book = ask_book_id(book_id,hash,pattern)
213
163
  end
214
164
 
215
165
  # download
@@ -225,38 +175,32 @@ module Bookscan
225
175
 
226
176
  def tune
227
177
  opt = OptionParser.new
228
- hash = nil
229
- dry_run = false
178
+ hash = nil; pattern = ".*"; dry_run = false
230
179
  opt.on('-g HASH','--group=HASH', 'group hash') do |v|
231
180
  hash = v
232
181
  end
233
182
  opt.on('--dry-run', 'dry-run mode') do |v|
234
183
  dry_run = true
235
184
  end
185
+ opt.on('-m PATTERN','--match=PATTERN','pattern match') do |v|
186
+ pattern = v
187
+ end
236
188
  opt.parse!(@command_options)
237
189
  book_id = @command_options.shift
238
- type = @command_options.shift
239
- unless type
240
- type = ask('Enter tune type: ',TUNE_TYPES) do |q|
241
- q.validate = /\w+/
242
- q.readline = true
243
- end
244
- end
190
+ type = ask_tune_type(@command_options.shift)
245
191
 
246
192
  if book_id == "all"
247
193
  tuned = @cache.tuned
248
- bs = @cache.books
249
- bs.each { |book|
194
+ @cache.books.each { |book|
195
+ next unless /#{pattern}/ =~ book.title
250
196
  unless @cache.tuned?(book,type)
251
197
  # tune
252
- unless dry_run
253
- start
254
- end
198
+ start unless dry_run
255
199
  puts "tune for %s: %s" % [type, book.title] if dry_run or @agent.tune(book,type)
256
200
  end
257
201
  }
258
202
  else
259
- book = ask_book_id(book_id,hash)
203
+ book = ask_book_id(book_id,hash,pattern)
260
204
  # tune
261
205
  puts "tune for %s: %s" % [type, book.title]
262
206
  unless dry_run
@@ -276,5 +220,75 @@ module Bookscan
276
220
  puts @cache.tuned.to_s
277
221
  end
278
222
 
223
+ private
224
+
225
+ def ask_group(hash,gs)
226
+ unless hash
227
+ puts gs.to_s
228
+ hash = ask('Enter hash ([q]uit): ',gs.hashes << 'q') do |q|
229
+ q.validate = /\w+/
230
+ q.readline = true
231
+ end
232
+ end
233
+ raise SystemExit if hash == "q"
234
+
235
+ gs.by_hash(hash)
236
+ end
237
+
238
+ def ask_tune_type(type)
239
+ unless type
240
+ type = ask('Enter tune type ([q]uit): ',TUNE_TYPES.clone << 'q') do |q|
241
+ q.validate = /\w+/
242
+ q.readline = true
243
+ end
244
+ end
245
+ raise SystemExit if type == "q"
246
+ type
247
+ end
248
+
249
+ def ask_tuned_book_id(book_id,type,pattern)
250
+ type = ask_tune_type(type)
251
+
252
+ ts = @cache.tuned.delete_if do |i|
253
+ i.tune_type != type
254
+ end
255
+
256
+ raise "No tuned in cache. Exceute 'bookscan update' first." unless ts.length > 0
257
+ return ask_book_id_pattern(book_id,ts,pattern)
258
+ end
259
+
260
+ def ask_book_id_pattern(book_id,books,pattern)
261
+ bs = books.clone.delete_if { |i|
262
+ !(/#{pattern}/ =~ i.title)
263
+ }
264
+ unless book_id
265
+ puts bs.to_s
266
+ book_id = ask('Enter book id ([q]uit): ',bs.ids << 'q') do |q|
267
+ q.validate = /\w+/
268
+ q.readline = true
269
+ end
270
+ raise SystemExit if book_id == "q"
271
+ end
272
+ bs.by_id(book_id)
273
+ end
274
+
275
+ def ask_book_id(book_id,hash,pattern)
276
+ unless pattern == ".*"
277
+ return ask_book_id_pattern(book_id,@cache.books,pattern)
278
+ end
279
+
280
+ gs = @cache.groups
281
+ unless book_id
282
+ g = ask_group(hash,gs)
283
+ puts g.books.to_s
284
+ book_id = ask('Enter book id ([q]uit): ',g.books.ids << 'q') do |q|
285
+ q.validate = /\w+/
286
+ q.readline = true
287
+ end
288
+ raise SystemExit if book_id == "q"
289
+ end
290
+ gs.book(book_id)
291
+ end
292
+
279
293
  end
280
294
  end
metadata CHANGED
@@ -2,12 +2,12 @@
2
2
  name: bookscan
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 19
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yoshihiro TAKAHARA
@@ -19,7 +19,7 @@ date: 2011-01-19 00:00:00 +09:00
19
19
  default_executable: bookscan
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
22
+ type: :development
23
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
@@ -30,10 +30,10 @@ dependencies:
30
30
  - 0
31
31
  version: "0"
32
32
  requirement: *id001
33
+ prerelease: false
33
34
  name: shoulda
34
- type: :development
35
35
  - !ruby/object:Gem::Dependency
36
- prerelease: false
36
+ type: :development
37
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
@@ -46,10 +46,10 @@ dependencies:
46
46
  - 0
47
47
  version: 1.0.0
48
48
  requirement: *id002
49
+ prerelease: false
49
50
  name: bundler
50
- type: :development
51
51
  - !ruby/object:Gem::Dependency
52
- prerelease: false
52
+ type: :development
53
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
@@ -62,10 +62,10 @@ dependencies:
62
62
  - 2
63
63
  version: 1.5.2
64
64
  requirement: *id003
65
+ prerelease: false
65
66
  name: jeweler
66
- type: :development
67
67
  - !ruby/object:Gem::Dependency
68
- prerelease: false
68
+ type: :development
69
69
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
@@ -76,10 +76,10 @@ dependencies:
76
76
  - 0
77
77
  version: "0"
78
78
  requirement: *id004
79
+ prerelease: false
79
80
  name: rcov
80
- type: :development
81
81
  - !ruby/object:Gem::Dependency
82
- prerelease: false
82
+ type: :runtime
83
83
  version_requirements: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -90,10 +90,10 @@ dependencies:
90
90
  - 0
91
91
  version: "0"
92
92
  requirement: *id005
93
+ prerelease: false
93
94
  name: mutter
94
- type: :runtime
95
95
  - !ruby/object:Gem::Dependency
96
- prerelease: false
96
+ type: :runtime
97
97
  version_requirements: &id006 !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
@@ -105,10 +105,10 @@ dependencies:
105
105
  - 1
106
106
  version: "0.1"
107
107
  requirement: *id006
108
+ prerelease: false
108
109
  name: keystorage
109
- type: :runtime
110
110
  - !ruby/object:Gem::Dependency
111
- prerelease: false
111
+ type: :runtime
112
112
  version_requirements: &id007 !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -121,10 +121,10 @@ dependencies:
121
121
  - 0
122
122
  version: 1.0.0
123
123
  requirement: *id007
124
+ prerelease: false
124
125
  name: mechanize
125
- type: :runtime
126
126
  - !ruby/object:Gem::Dependency
127
- prerelease: false
127
+ type: :runtime
128
128
  version_requirements: &id008 !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -136,8 +136,8 @@ dependencies:
136
136
  - 6
137
137
  version: "1.6"
138
138
  requirement: *id008
139
+ prerelease: false
139
140
  name: highline
140
- type: :runtime
141
141
  description: This is a scraper of Bookscan (http://www.bookscan.co.jp) Service.This is *NOT* a official software of Bookscan.
142
142
  email: y.takahara@gmail.com
143
143
  executables:
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements: []
196
196
 
197
197
  rubyforge_project:
198
- rubygems_version: 1.3.7
198
+ rubygems_version: 1.4.2
199
199
  signing_key:
200
200
  specification_version: 3
201
201
  summary: BookScan Scraper