klipbook 1.0.2 → 2.0.0

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.
Files changed (41) hide show
  1. data/CHANGELOG.txt +13 -0
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +17 -6
  4. data/LICENSE.txt +1 -1
  5. data/README.md +64 -32
  6. data/bin/klipbook +45 -9
  7. data/features/collate.feature +6 -46
  8. data/features/pretty_print.feature +51 -0
  9. data/features/step_definitions/collate_steps.rb +8 -52
  10. data/features/step_definitions/pretty_print_steps.rb +61 -0
  11. data/klipbook.gemspec +25 -20
  12. data/lib/klipbook/collate/book_file.rb +54 -0
  13. data/lib/klipbook/commands/collate.rb +17 -0
  14. data/lib/klipbook/commands/list_books.rb +19 -0
  15. data/lib/klipbook/commands/pretty_print.rb +17 -0
  16. data/lib/klipbook/{output/html_summary_writer.rb → pretty_print/html_printer.rb} +4 -5
  17. data/lib/klipbook/sources/amazon_site/book_scraper.rb +3 -3
  18. data/lib/klipbook/sources/book.rb +28 -0
  19. data/lib/klipbook/{fetcher.rb → sources/book_source.rb} +7 -10
  20. data/lib/klipbook/sources/clipping.rb +11 -0
  21. data/lib/klipbook/sources/kindle_device/file.rb +4 -4
  22. data/lib/klipbook/util/struct_to_json.rb +11 -0
  23. data/lib/klipbook/version.rb +1 -1
  24. data/lib/klipbook.rb +13 -10
  25. data/spec/lib/klipbook/collate/book_file_spec.rb +73 -0
  26. data/spec/lib/klipbook/{printer_spec.rb → commands/list_books_spec.rb} +5 -5
  27. data/spec/lib/klipbook/commands/pretty_print_spec.rb +40 -0
  28. data/spec/lib/klipbook/{output/html_summary_writer_spec.rb → pretty_print/html_printer_spec.rb} +4 -4
  29. data/spec/lib/klipbook/{fetcher_spec.rb → sources/book_source_spec.rb} +12 -12
  30. data/spec/lib/klipbook/{book_spec.rb → sources/book_spec.rb} +2 -2
  31. data/spec/lib/klipbook/sources/kindle_device/file_spec.rb +24 -4
  32. metadata +24 -19
  33. data/lib/klipbook/book.rb +0 -18
  34. data/lib/klipbook/clipping.rb +0 -9
  35. data/lib/klipbook/collator.rb +0 -17
  36. data/lib/klipbook/output/book_helpers.rb +0 -12
  37. data/lib/klipbook/printer.rb +0 -18
  38. data/spec/lib/klipbook/collator_spec.rb +0 -40
  39. /data/lib/klipbook/{output → pretty_print}/html_book_summary.erb +0 -0
  40. /data/lib/klipbook/{invalid_source_error.rb → sources/invalid_source_error.rb} +0 -0
  41. /data/lib/klipbook/{blank.rb → util/blank.rb} +0 -0
@@ -7,7 +7,7 @@ describe Klipbook::Book do
7
7
 
8
8
  context 'with no author' do
9
9
  let(:book) do
10
- Klipbook::Book.new do |b|
10
+ Klipbook::Book.new.tap do |b|
11
11
  b.title = 'Book title'
12
12
  end
13
13
  end
@@ -19,7 +19,7 @@ describe Klipbook::Book do
19
19
 
20
20
  context 'with an author' do
21
21
  let(:book) do
22
- Klipbook::Book.new do |b|
22
+ Klipbook::Book.new.tap do |b|
23
23
  b.title = 'Book title'
24
24
  b.author = 'Rob Ripjaw'
25
25
  end
@@ -2,18 +2,38 @@ require 'spec_helper'
2
2
 
3
3
  describe Klipbook::Sources::KindleDevice::File do
4
4
 
5
- let(:file) { Klipbook::Sources::KindleDevice::File.new('file text', max_books, file_parser) }
5
+ let(:file) { Klipbook::Sources::KindleDevice::File.new('file path', max_books, file_parser) }
6
6
 
7
- let (:max_books) { 30 }
7
+ let(:max_books) { 30 }
8
8
 
9
- let (:entries) { [] }
9
+ let(:entries) { [] }
10
10
 
11
- let (:file_parser) do
11
+ let(:file_parser) do
12
12
  Object.new.tap do |fake_parser|
13
13
  stub(fake_parser).extract_entries { entries }
14
14
  end
15
15
  end
16
16
 
17
+ let(:input_file) do
18
+ Object.new.tap do |fake_file|
19
+ stub(fake_file).read { 'file text' }
20
+ end
21
+ end
22
+
23
+ before :each do
24
+ stub(File).open.returns do |*args|
25
+ passed_block = args.last
26
+ passed_block.call(input_file)
27
+ end
28
+ end
29
+
30
+ describe 'initially' do
31
+ it 'reads the contents of the input file' do
32
+ file
33
+ File.should have_received.open('file path', 'r')
34
+ end
35
+ end
36
+
17
37
  describe '#books' do
18
38
  subject { file.books }
19
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klipbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-12 00:00:00.000000000 Z
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
@@ -140,7 +140,7 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: pry
143
+ name: pry-debugger
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
@@ -276,34 +276,39 @@ files:
276
276
  - features/collate.feature
277
277
  - features/fixtures/clippings-for-three-books.txt
278
278
  - features/list.feature
279
+ - features/pretty_print.feature
279
280
  - features/step_definitions/collate_steps.rb
280
281
  - features/step_definitions/list_steps.rb
282
+ - features/step_definitions/pretty_print_steps.rb
281
283
  - features/support/env.rb
282
284
  - klipbook.gemspec
283
285
  - lib/klipbook.rb
284
- - lib/klipbook/blank.rb
285
- - lib/klipbook/book.rb
286
- - lib/klipbook/clipping.rb
287
- - lib/klipbook/collator.rb
286
+ - lib/klipbook/collate/book_file.rb
287
+ - lib/klipbook/commands/collate.rb
288
+ - lib/klipbook/commands/list_books.rb
289
+ - lib/klipbook/commands/pretty_print.rb
288
290
  - lib/klipbook/config.rb
289
- - lib/klipbook/fetcher.rb
290
- - lib/klipbook/invalid_source_error.rb
291
- - lib/klipbook/output/book_helpers.rb
292
- - lib/klipbook/output/html_book_summary.erb
293
- - lib/klipbook/output/html_summary_writer.rb
294
- - lib/klipbook/printer.rb
291
+ - lib/klipbook/pretty_print/html_book_summary.erb
292
+ - lib/klipbook/pretty_print/html_printer.rb
295
293
  - lib/klipbook/sources/amazon_site/book_scraper.rb
296
294
  - lib/klipbook/sources/amazon_site/site_scraper.rb
295
+ - lib/klipbook/sources/book.rb
296
+ - lib/klipbook/sources/book_source.rb
297
+ - lib/klipbook/sources/clipping.rb
298
+ - lib/klipbook/sources/invalid_source_error.rb
297
299
  - lib/klipbook/sources/kindle_device/entry.rb
298
300
  - lib/klipbook/sources/kindle_device/entry_parser.rb
299
301
  - lib/klipbook/sources/kindle_device/file.rb
300
302
  - lib/klipbook/sources/kindle_device/file_parser.rb
303
+ - lib/klipbook/util/blank.rb
304
+ - lib/klipbook/util/struct_to_json.rb
301
305
  - lib/klipbook/version.rb
302
- - spec/lib/klipbook/book_spec.rb
303
- - spec/lib/klipbook/collator_spec.rb
304
- - spec/lib/klipbook/fetcher_spec.rb
305
- - spec/lib/klipbook/output/html_summary_writer_spec.rb
306
- - spec/lib/klipbook/printer_spec.rb
306
+ - spec/lib/klipbook/collate/book_file_spec.rb
307
+ - spec/lib/klipbook/commands/list_books_spec.rb
308
+ - spec/lib/klipbook/commands/pretty_print_spec.rb
309
+ - spec/lib/klipbook/pretty_print/html_printer_spec.rb
310
+ - spec/lib/klipbook/sources/book_source_spec.rb
311
+ - spec/lib/klipbook/sources/book_spec.rb
307
312
  - spec/lib/klipbook/sources/kindle_device/entry_parser_spec.rb
308
313
  - spec/lib/klipbook/sources/kindle_device/file_parser_spec.rb
309
314
  - spec/lib/klipbook/sources/kindle_device/file_spec.rb
@@ -325,7 +330,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
325
330
  version: '0'
326
331
  segments:
327
332
  - 0
328
- hash: -4595890160696464397
333
+ hash: -33745898634206631
329
334
  required_rubygems_version: !ruby/object:Gem::Requirement
330
335
  none: false
331
336
  requirements:
data/lib/klipbook/book.rb DELETED
@@ -1,18 +0,0 @@
1
- module Klipbook
2
- class Book
3
- attr_accessor :asin, :author, :title, :last_update, :clippings
4
-
5
- def initialize
6
- yield self if block_given?
7
- end
8
-
9
- def title_and_author
10
- author_txt = author ? " by #{author}" : ''
11
- "#{title}#{author_txt}"
12
- end
13
-
14
- def get_binding
15
- binding
16
- end
17
- end
18
- end
@@ -1,9 +0,0 @@
1
- module Klipbook
2
- class Clipping
3
- attr_accessor :annotation_id, :text, :location, :type, :page
4
-
5
- def initialize
6
- yield self if block_given?
7
- end
8
- end
9
- end
@@ -1,17 +0,0 @@
1
- module Klipbook
2
- class Collator
3
- def initialize(books, summary_writer=Klipbook::Output::HtmlSummaryWriter.new)
4
- @books = books
5
- @summary_writer = summary_writer
6
- end
7
-
8
- def collate_books(output_dir, force, message_stream=$stdout)
9
- message_stream.puts "Using output directory: #{output_dir}"
10
-
11
- @books.each do |book|
12
- @summary_writer.write(book, output_dir, force)
13
- end
14
- end
15
- end
16
- end
17
-
@@ -1,12 +0,0 @@
1
- module Klipbook::Output
2
- module BookHelpers
3
- def location_html(location)
4
- if self.asin
5
- "<a href=\"kindle://book?action=open&asin=#{asin}&location=#{location}\">loc #{location}</a>"
6
- else
7
- "loc #{location}"
8
- end
9
- end
10
- end
11
- end
12
-
@@ -1,18 +0,0 @@
1
- module Klipbook
2
- class Printer
3
- def initialize(books)
4
- @books = books
5
- end
6
-
7
- def print(output=$stdout)
8
- if @books.empty?
9
- output.puts 'No books available'
10
- else
11
- output.puts 'Book list:'
12
- @books.each_with_index do |book, index|
13
- output.puts "[#{index + 1}] #{book.title_and_author}"
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Klipbook::Collator do
4
-
5
- let (:it) { Klipbook::Collator.new(books, summary_writer) }
6
-
7
- let (:summary_writer) do
8
- Object.new.tap do |fake_writer|
9
- stub(fake_writer).write
10
- end
11
- end
12
-
13
- let (:message_stream) do
14
- Object.new.tap do |fake_stream|
15
- stub(fake_stream).puts
16
- end
17
- end
18
-
19
- let (:book_one) { Klipbook::Book.new }
20
- let (:book_two) { Klipbook::Book.new }
21
- let (:books) { [ book_one, book_two ] }
22
-
23
- let(:output_dir) { 'fake output dir' }
24
-
25
- describe '#collate_books' do
26
-
27
- subject { it.collate_books(output_dir, true, message_stream) }
28
-
29
- it 'prints a message displaying the output directory' do
30
- subject
31
- message_stream.should have_received.puts('Using output directory: fake output dir')
32
- end
33
-
34
- it 'passes each book to the summary writer' do
35
- subject
36
- summary_writer.should have_received.write(book_one, output_dir, true)
37
- summary_writer.should have_received.write(book_two, output_dir, true)
38
- end
39
- end
40
- end
File without changes