klipbook 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +13 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -6
- data/LICENSE.txt +1 -1
- data/README.md +64 -32
- data/bin/klipbook +45 -9
- data/features/collate.feature +6 -46
- data/features/pretty_print.feature +51 -0
- data/features/step_definitions/collate_steps.rb +8 -52
- data/features/step_definitions/pretty_print_steps.rb +61 -0
- data/klipbook.gemspec +25 -20
- data/lib/klipbook/collate/book_file.rb +54 -0
- data/lib/klipbook/commands/collate.rb +17 -0
- data/lib/klipbook/commands/list_books.rb +19 -0
- data/lib/klipbook/commands/pretty_print.rb +17 -0
- data/lib/klipbook/{output/html_summary_writer.rb → pretty_print/html_printer.rb} +4 -5
- data/lib/klipbook/sources/amazon_site/book_scraper.rb +3 -3
- data/lib/klipbook/sources/book.rb +28 -0
- data/lib/klipbook/{fetcher.rb → sources/book_source.rb} +7 -10
- data/lib/klipbook/sources/clipping.rb +11 -0
- data/lib/klipbook/sources/kindle_device/file.rb +4 -4
- data/lib/klipbook/util/struct_to_json.rb +11 -0
- data/lib/klipbook/version.rb +1 -1
- data/lib/klipbook.rb +13 -10
- data/spec/lib/klipbook/collate/book_file_spec.rb +73 -0
- data/spec/lib/klipbook/{printer_spec.rb → commands/list_books_spec.rb} +5 -5
- data/spec/lib/klipbook/commands/pretty_print_spec.rb +40 -0
- data/spec/lib/klipbook/{output/html_summary_writer_spec.rb → pretty_print/html_printer_spec.rb} +4 -4
- data/spec/lib/klipbook/{fetcher_spec.rb → sources/book_source_spec.rb} +12 -12
- data/spec/lib/klipbook/{book_spec.rb → sources/book_spec.rb} +2 -2
- data/spec/lib/klipbook/sources/kindle_device/file_spec.rb +24 -4
- metadata +24 -19
- data/lib/klipbook/book.rb +0 -18
- data/lib/klipbook/clipping.rb +0 -9
- data/lib/klipbook/collator.rb +0 -17
- data/lib/klipbook/output/book_helpers.rb +0 -12
- data/lib/klipbook/printer.rb +0 -18
- data/spec/lib/klipbook/collator_spec.rb +0 -40
- /data/lib/klipbook/{output → pretty_print}/html_book_summary.erb +0 -0
- /data/lib/klipbook/{invalid_source_error.rb → sources/invalid_source_error.rb} +0 -0
- /data/lib/klipbook/{blank.rb → util/blank.rb} +0 -0
data/klipbook.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "klipbook"
|
8
|
-
s.version = "
|
8
|
+
s.version = "2.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ray Grasso"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-02-13"
|
13
13
|
s.description = "Process your Kindle clippings file to generate a nicely formatted compilation of the clippings of the books you've read"
|
14
14
|
s.email = "ray.grasso@gmail.com"
|
15
15
|
s.executables = ["klipbook"]
|
@@ -33,34 +33,39 @@ Gem::Specification.new do |s|
|
|
33
33
|
"features/collate.feature",
|
34
34
|
"features/fixtures/clippings-for-three-books.txt",
|
35
35
|
"features/list.feature",
|
36
|
+
"features/pretty_print.feature",
|
36
37
|
"features/step_definitions/collate_steps.rb",
|
37
38
|
"features/step_definitions/list_steps.rb",
|
39
|
+
"features/step_definitions/pretty_print_steps.rb",
|
38
40
|
"features/support/env.rb",
|
39
41
|
"klipbook.gemspec",
|
40
42
|
"lib/klipbook.rb",
|
41
|
-
"lib/klipbook/
|
42
|
-
"lib/klipbook/
|
43
|
-
"lib/klipbook/
|
44
|
-
"lib/klipbook/
|
43
|
+
"lib/klipbook/collate/book_file.rb",
|
44
|
+
"lib/klipbook/commands/collate.rb",
|
45
|
+
"lib/klipbook/commands/list_books.rb",
|
46
|
+
"lib/klipbook/commands/pretty_print.rb",
|
45
47
|
"lib/klipbook/config.rb",
|
46
|
-
"lib/klipbook/
|
47
|
-
"lib/klipbook/
|
48
|
-
"lib/klipbook/output/book_helpers.rb",
|
49
|
-
"lib/klipbook/output/html_book_summary.erb",
|
50
|
-
"lib/klipbook/output/html_summary_writer.rb",
|
51
|
-
"lib/klipbook/printer.rb",
|
48
|
+
"lib/klipbook/pretty_print/html_book_summary.erb",
|
49
|
+
"lib/klipbook/pretty_print/html_printer.rb",
|
52
50
|
"lib/klipbook/sources/amazon_site/book_scraper.rb",
|
53
51
|
"lib/klipbook/sources/amazon_site/site_scraper.rb",
|
52
|
+
"lib/klipbook/sources/book.rb",
|
53
|
+
"lib/klipbook/sources/book_source.rb",
|
54
|
+
"lib/klipbook/sources/clipping.rb",
|
55
|
+
"lib/klipbook/sources/invalid_source_error.rb",
|
54
56
|
"lib/klipbook/sources/kindle_device/entry.rb",
|
55
57
|
"lib/klipbook/sources/kindle_device/entry_parser.rb",
|
56
58
|
"lib/klipbook/sources/kindle_device/file.rb",
|
57
59
|
"lib/klipbook/sources/kindle_device/file_parser.rb",
|
60
|
+
"lib/klipbook/util/blank.rb",
|
61
|
+
"lib/klipbook/util/struct_to_json.rb",
|
58
62
|
"lib/klipbook/version.rb",
|
59
|
-
"spec/lib/klipbook/
|
60
|
-
"spec/lib/klipbook/
|
61
|
-
"spec/lib/klipbook/
|
62
|
-
"spec/lib/klipbook/
|
63
|
-
"spec/lib/klipbook/
|
63
|
+
"spec/lib/klipbook/collate/book_file_spec.rb",
|
64
|
+
"spec/lib/klipbook/commands/list_books_spec.rb",
|
65
|
+
"spec/lib/klipbook/commands/pretty_print_spec.rb",
|
66
|
+
"spec/lib/klipbook/pretty_print/html_printer_spec.rb",
|
67
|
+
"spec/lib/klipbook/sources/book_source_spec.rb",
|
68
|
+
"spec/lib/klipbook/sources/book_spec.rb",
|
64
69
|
"spec/lib/klipbook/sources/kindle_device/entry_parser_spec.rb",
|
65
70
|
"spec/lib/klipbook/sources/kindle_device/file_parser_spec.rb",
|
66
71
|
"spec/lib/klipbook/sources/kindle_device/file_spec.rb",
|
@@ -86,7 +91,7 @@ Gem::Specification.new do |s|
|
|
86
91
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
87
92
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
88
93
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
89
|
-
s.add_development_dependency(%q<pry>, [">= 0"])
|
94
|
+
s.add_development_dependency(%q<pry-debugger>, [">= 0"])
|
90
95
|
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
91
96
|
s.add_development_dependency(%q<aruba>, [">= 0"])
|
92
97
|
s.add_development_dependency(%q<guard>, [">= 0"])
|
@@ -102,7 +107,7 @@ Gem::Specification.new do |s|
|
|
102
107
|
s.add_dependency(%q<bundler>, [">= 0"])
|
103
108
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
104
109
|
s.add_dependency(%q<rcov>, [">= 0"])
|
105
|
-
s.add_dependency(%q<pry>, [">= 0"])
|
110
|
+
s.add_dependency(%q<pry-debugger>, [">= 0"])
|
106
111
|
s.add_dependency(%q<cucumber>, [">= 0"])
|
107
112
|
s.add_dependency(%q<aruba>, [">= 0"])
|
108
113
|
s.add_dependency(%q<guard>, [">= 0"])
|
@@ -119,7 +124,7 @@ Gem::Specification.new do |s|
|
|
119
124
|
s.add_dependency(%q<bundler>, [">= 0"])
|
120
125
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
121
126
|
s.add_dependency(%q<rcov>, [">= 0"])
|
122
|
-
s.add_dependency(%q<pry>, [">= 0"])
|
127
|
+
s.add_dependency(%q<pry-debugger>, [">= 0"])
|
123
128
|
s.add_dependency(%q<cucumber>, [">= 0"])
|
124
129
|
s.add_dependency(%q<aruba>, [">= 0"])
|
125
130
|
s.add_dependency(%q<guard>, [">= 0"])
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Klipbook::Collate
|
4
|
+
class BookFile
|
5
|
+
attr_reader :books
|
6
|
+
|
7
|
+
def self.from_json(raw_json)
|
8
|
+
if raw_json.blank?
|
9
|
+
books = []
|
10
|
+
else
|
11
|
+
objs = JSON.parse(raw_json)
|
12
|
+
books = objs.map { |o| Klipbook::Book.from_hash(o) }
|
13
|
+
end
|
14
|
+
self.new(books)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(books)
|
18
|
+
@books = books || []
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_books(new_books, force, message_stream=$stdout)
|
22
|
+
new_books.each do |new_book|
|
23
|
+
if book_exists?(new_book)
|
24
|
+
replace_book(new_book, message_stream) if force
|
25
|
+
else
|
26
|
+
message_stream.puts "Adding: #{new_book.title_and_author}"
|
27
|
+
@books.push(new_book)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_json
|
33
|
+
JSON.pretty_generate(@books)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def book_exists?(new_book)
|
39
|
+
find_book(new_book)
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_book(new_book)
|
43
|
+
@books.find { |existing_book| existing_book.title_and_author == new_book.title_and_author }
|
44
|
+
end
|
45
|
+
|
46
|
+
def replace_book(new_book, message_stream)
|
47
|
+
message_stream.puts "Updating: #{new_book.title_and_author}"
|
48
|
+
|
49
|
+
old_book = find_book(new_book)
|
50
|
+
@books.delete(old_book)
|
51
|
+
@books.push(new_book)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Klipbook::Commands
|
2
|
+
class Collate
|
3
|
+
def initialize(books, book_file)
|
4
|
+
@books = books
|
5
|
+
@book_file = book_file
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(output_file_path, force, message_stream=$stdout)
|
9
|
+
File.open(output_file_path, 'w') do |output_file|
|
10
|
+
@book_file.add_books(@books, force)
|
11
|
+
|
12
|
+
message_stream.puts "\nWriting book json to file: #{output_file.path}"
|
13
|
+
output_file.puts @book_file.to_json
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Klipbook::Commands
|
2
|
+
class ListBooks
|
3
|
+
def initialize(books)
|
4
|
+
@books = books
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(output_stream=$stdout)
|
8
|
+
if @books.empty?
|
9
|
+
output_stream.puts 'No books available'
|
10
|
+
else
|
11
|
+
output_stream.puts 'Book list:'
|
12
|
+
@books.each_with_index do |book, index|
|
13
|
+
output_stream.puts "[#{index + 1}] #{book.title_and_author}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Klipbook::Commands
|
2
|
+
class PrettyPrint
|
3
|
+
def initialize(books, pretty_printer=Klipbook::PrettyPrint::HtmlPrinter.new)
|
4
|
+
@books = books
|
5
|
+
@pretty_printer = pretty_printer
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(output_dir, force, message_stream=$stdout)
|
9
|
+
message_stream.puts "Using output directory: #{output_dir}"
|
10
|
+
|
11
|
+
@books.each do |book|
|
12
|
+
@pretty_printer.print_to_file(book, output_dir, force)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'erb'
|
2
2
|
|
3
|
-
module Klipbook::
|
4
|
-
class
|
3
|
+
module Klipbook::PrettyPrint
|
4
|
+
class HtmlPrinter
|
5
5
|
def initialize(message_stream=$stdout)
|
6
6
|
@message_stream = message_stream
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def print_to_file(book, output_dir, force)
|
10
10
|
require 'rainbow'
|
11
11
|
|
12
|
-
book.extend Klipbook::Output::BookHelpers
|
13
|
-
|
14
12
|
filename = filename_for_book(book)
|
15
13
|
filepath = File.join(output_dir, filename)
|
16
14
|
|
@@ -38,5 +36,6 @@ module Klipbook::Output
|
|
38
36
|
def template
|
39
37
|
@template ||= File.read(File.join(File.dirname(__FILE__), 'html_book_summary.erb'))
|
40
38
|
end
|
39
|
+
|
41
40
|
end
|
42
41
|
end
|
@@ -11,7 +11,7 @@ module Klipbook::Sources
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def build_book(page, element)
|
14
|
-
Klipbook::Book.new do |b|
|
14
|
+
Klipbook::Book.new.tap do |b|
|
15
15
|
b.asin = element.attribute("id").value.gsub(/_[0-9]+$/, "")
|
16
16
|
b.author = element.xpath("span[@class='author']").text.gsub("\n", "").gsub(" by ", "").strip
|
17
17
|
b.title = element.xpath("span/a").text
|
@@ -34,7 +34,7 @@ module Klipbook::Sources
|
|
34
34
|
annotation_id = element.xpath("form/input[@id='annotation_id']").attribute("value").value
|
35
35
|
note_text = element.xpath("p/span[@class='noteContent']").text
|
36
36
|
|
37
|
-
highlight = Klipbook::Clipping.new do |c|
|
37
|
+
highlight = Klipbook::Clipping.new.tap do |c|
|
38
38
|
c.annotation_id = annotation_id
|
39
39
|
c.text = element.xpath("span[@class='highlight']").text
|
40
40
|
c.type = :highlight
|
@@ -44,7 +44,7 @@ module Klipbook::Sources
|
|
44
44
|
if note_text.blank?
|
45
45
|
highlight
|
46
46
|
else
|
47
|
-
note = Klipbook::Clipping.new do |c|
|
47
|
+
note = Klipbook::Clipping.new.tap do |c|
|
48
48
|
c.annotation_id = annotation_id
|
49
49
|
c.text = note_text
|
50
50
|
c.type = :note
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Klipbook::Book = Struct.new(:asin, :author, :title, :last_update, :clippings) do
|
2
|
+
def title_and_author
|
3
|
+
author_txt = author ? " by #{author}" : ''
|
4
|
+
"#{title}#{author_txt}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_binding
|
8
|
+
binding
|
9
|
+
end
|
10
|
+
|
11
|
+
def location_html(location)
|
12
|
+
if self.asin
|
13
|
+
"<a href=\"kindle://book?action=open&asin=#{asin}&location=#{location}\">loc #{location}</a>"
|
14
|
+
else
|
15
|
+
"loc #{location}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_hash(hash)
|
20
|
+
self.new.tap do |b|
|
21
|
+
b.asin = hash['asin']
|
22
|
+
b.author = hash['author']
|
23
|
+
b.title = hash['title']
|
24
|
+
b.last_update = hash['last_update']
|
25
|
+
b.clippings = hash['clippings'].map { |clip| Klipbook::Clipping.from_hash(clip) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,29 +1,26 @@
|
|
1
|
-
module Klipbook
|
2
|
-
class
|
1
|
+
module Klipbook::Sources
|
2
|
+
class BookSource
|
3
3
|
def initialize(source_spec, max_books)
|
4
|
-
raise InvalidSourceError unless valid_source(source_spec)
|
4
|
+
raise InvalidSourceError unless valid_source?(source_spec)
|
5
5
|
|
6
6
|
if (source_spec =~ /file:(.+)/)
|
7
|
-
|
8
|
-
@source = Klipbook::Sources::KindleDevice::File.new(
|
7
|
+
file_path = $1
|
8
|
+
@source = Klipbook::Sources::KindleDevice::File.new(file_path, max_books)
|
9
9
|
elsif (source_spec =~ /site:(.+):(.+)/)
|
10
10
|
username = $1
|
11
11
|
password = $2
|
12
12
|
@source = Klipbook::Sources::AmazonSite::SiteScraper.new(username, password, max_books)
|
13
|
-
else
|
14
|
-
raise InvalidSourceError("Unrecognised source type. Only 'file' and 'site' are supported")
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
def
|
16
|
+
def books
|
19
17
|
@source.books
|
20
18
|
end
|
21
19
|
|
22
20
|
private
|
23
21
|
|
24
|
-
def valid_source(source_spec)
|
22
|
+
def valid_source?(source_spec)
|
25
23
|
source_spec =~ /(file:|site:.+:.+)/
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
29
|
-
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Klipbook::Clipping = Struct.new(:annotation_id, :text, :location, :type, :page) do
|
2
|
+
def self.from_hash(hash)
|
3
|
+
self.new.tap do |b|
|
4
|
+
b.annotation_id = hash['annotation_id']
|
5
|
+
b.text = hash['text']
|
6
|
+
b.location = hash['location']
|
7
|
+
b.type = hash['type']
|
8
|
+
b.page = hash['page']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Klipbook::Sources
|
2
2
|
module KindleDevice
|
3
3
|
class File
|
4
|
-
def initialize(
|
5
|
-
@file_text =
|
4
|
+
def initialize(file_path, max_books, file_parser=FileParser.new)
|
5
|
+
@file_text = ::File.open(file_path, 'r') {|f| f.read.strip }
|
6
6
|
@file_parser = file_parser
|
7
7
|
@max_books = max_books
|
8
8
|
end
|
@@ -38,12 +38,12 @@ module Klipbook::Sources
|
|
38
38
|
def book_from_entries(entries)
|
39
39
|
entries.sort! { |ea, eb| ea.location <=> eb.location }
|
40
40
|
|
41
|
-
Klipbook::Book.new do |b|
|
41
|
+
Klipbook::Book.new.tap do |b|
|
42
42
|
b.title = entries.first.title
|
43
43
|
b.author = entries.first.author
|
44
44
|
b.last_update = entries.map(&:added_on).max
|
45
45
|
b.clippings = entries.map do |e|
|
46
|
-
Klipbook::Clipping.new do |c|
|
46
|
+
Klipbook::Clipping.new.tap do |c|
|
47
47
|
c.location = e.location
|
48
48
|
c.page = e.page
|
49
49
|
c.text = e.text
|
data/lib/klipbook/version.rb
CHANGED
data/lib/klipbook.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'klipbook/blank'
|
2
|
+
require 'klipbook/util/blank'
|
3
|
+
require 'klipbook/util/struct_to_json'
|
3
4
|
require 'klipbook/version'
|
4
5
|
|
6
|
+
require 'klipbook/commands/collate'
|
7
|
+
require 'klipbook/commands/list_books'
|
8
|
+
require 'klipbook/commands/pretty_print'
|
9
|
+
|
10
|
+
require 'klipbook/sources/book_source'
|
11
|
+
require 'klipbook/sources/book'
|
12
|
+
require 'klipbook/sources/clipping'
|
13
|
+
require 'klipbook/sources/invalid_source_error'
|
14
|
+
|
5
15
|
require 'klipbook/sources/kindle_device/file_parser'
|
6
16
|
require 'klipbook/sources/kindle_device/entry_parser'
|
7
17
|
require 'klipbook/sources/kindle_device/entry'
|
@@ -10,14 +20,7 @@ require 'klipbook/sources/kindle_device/file'
|
|
10
20
|
require 'klipbook/sources/amazon_site/site_scraper'
|
11
21
|
require 'klipbook/sources/amazon_site/book_scraper'
|
12
22
|
|
13
|
-
require 'klipbook/invalid_source_error'
|
14
23
|
require 'klipbook/config'
|
15
|
-
require 'klipbook/book'
|
16
|
-
require 'klipbook/clipping'
|
17
|
-
|
18
|
-
require 'klipbook/fetcher'
|
19
|
-
require 'klipbook/collator'
|
20
|
-
require 'klipbook/printer'
|
21
24
|
|
22
|
-
require 'klipbook/
|
23
|
-
require 'klipbook/
|
25
|
+
require 'klipbook/pretty_print/html_printer'
|
26
|
+
require 'klipbook/collate/book_file'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Klipbook::Collate::BookFile do
|
4
|
+
|
5
|
+
describe '.from_json' do
|
6
|
+
|
7
|
+
subject { Klipbook::Collate::BookFile.from_json(json) }
|
8
|
+
|
9
|
+
context 'with empty json' do
|
10
|
+
|
11
|
+
let(:json) { '' }
|
12
|
+
|
13
|
+
its(:books) { should be_empty }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#add_books' do
|
18
|
+
let (:message_stream) do
|
19
|
+
Object.new.tap do |fake_stream|
|
20
|
+
stub(fake_stream).puts
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:it) do
|
25
|
+
books = [
|
26
|
+
Klipbook::Book.new.tap do |b|
|
27
|
+
b.title = "Book one"
|
28
|
+
b.author = "Author one"
|
29
|
+
end,
|
30
|
+
Klipbook::Book.new.tap do |b|
|
31
|
+
b.title = "Book two"
|
32
|
+
b.author = "Author two"
|
33
|
+
end
|
34
|
+
]
|
35
|
+
Klipbook::Collate::BookFile.new(books)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "adds any books that don't already exist" do
|
39
|
+
new_book = Klipbook::Book.new.tap do |b|
|
40
|
+
b.title = 'Book three'
|
41
|
+
b.author = 'Author two'
|
42
|
+
end
|
43
|
+
|
44
|
+
it.add_books([ new_book ], false, message_stream)
|
45
|
+
it.books.should have(3).items
|
46
|
+
it.books.should include(new_book)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "replaces books that exist if force is true" do
|
50
|
+
new_book = Klipbook::Book.new.tap do |b|
|
51
|
+
b.title = 'Book one'
|
52
|
+
b.author = 'Author one'
|
53
|
+
b.asin = 'new asin'
|
54
|
+
end
|
55
|
+
|
56
|
+
it.add_books([ new_book ], true, message_stream)
|
57
|
+
it.books.should have(2).items
|
58
|
+
it.books.should include(new_book)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "does not replace existing books if force is false" do
|
62
|
+
new_book = Klipbook::Book.new.tap do |b|
|
63
|
+
b.title = 'Book one'
|
64
|
+
b.author = 'Author one'
|
65
|
+
b.asin = 'new asin'
|
66
|
+
end
|
67
|
+
|
68
|
+
it.add_books([ new_book ], false, message_stream)
|
69
|
+
it.books.should have(2).items
|
70
|
+
it.books.should_not include(new_book)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Klipbook::
|
3
|
+
describe Klipbook::Commands::ListBooks do
|
4
4
|
|
5
5
|
let (:output) do
|
6
6
|
Object.new.tap do |fake_output|
|
@@ -8,9 +8,9 @@ describe Klipbook::Printer do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe '#
|
11
|
+
describe '#call' do
|
12
12
|
|
13
|
-
subject { Klipbook::
|
13
|
+
subject { Klipbook::Commands::ListBooks.new(books).call(output) }
|
14
14
|
|
15
15
|
context 'when created with no books' do
|
16
16
|
|
@@ -25,8 +25,8 @@ describe Klipbook::Printer do
|
|
25
25
|
context 'when created with multiple books' do
|
26
26
|
let (:books) do
|
27
27
|
[
|
28
|
-
Klipbook::Book.new { |b| b.title = 'My first fake title' },
|
29
|
-
Klipbook::Book.new { |b| b.title = 'Another fake book'; b.author = 'Rock Riphard' }
|
28
|
+
Klipbook::Book.new.tap { |b| b.title = 'My first fake title' },
|
29
|
+
Klipbook::Book.new.tap { |b| b.title = 'Another fake book'; b.author = 'Rock Riphard' }
|
30
30
|
]
|
31
31
|
end
|
32
32
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Klipbook::Commands::PrettyPrint do
|
4
|
+
|
5
|
+
let (:it) { Klipbook::Commands::PrettyPrint.new(books, pretty_printer) }
|
6
|
+
|
7
|
+
let (:pretty_printer) do
|
8
|
+
Object.new.tap do |fake_printer|
|
9
|
+
stub(fake_printer).print_to_file
|
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('book one') }
|
20
|
+
let (:book_two) { Klipbook::Book.new('book two') }
|
21
|
+
let (:books) { [ book_one, book_two ] }
|
22
|
+
|
23
|
+
let(:output_dir) { 'fake output dir' }
|
24
|
+
|
25
|
+
describe '#call' do
|
26
|
+
|
27
|
+
subject { it.call(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 pretty printer' do
|
35
|
+
subject
|
36
|
+
pretty_printer.should have_received.print_to_file(book_one, output_dir, true)
|
37
|
+
pretty_printer.should have_received.print_to_file(book_two, output_dir, true)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/lib/klipbook/{output/html_summary_writer_spec.rb → pretty_print/html_printer_spec.rb}
RENAMED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
# This is more of an integration test but what the heck
|
4
4
|
# it can live in here for now
|
5
5
|
|
6
|
-
describe Klipbook::
|
6
|
+
describe Klipbook::PrettyPrint::HtmlPrinter do
|
7
7
|
|
8
8
|
before(:all) do
|
9
9
|
@output_dir = Dir.mktmpdir
|
@@ -14,7 +14,7 @@ describe Klipbook::Output::HtmlSummaryWriter do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:book) do
|
17
|
-
Klipbook::Book.new do |b|
|
17
|
+
Klipbook::Book.new.tap do |b|
|
18
18
|
b.title = 'Fake book title'
|
19
19
|
b.author = 'Fake Author'
|
20
20
|
b.clippings = []
|
@@ -27,9 +27,9 @@ describe Klipbook::Output::HtmlSummaryWriter do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe '#
|
30
|
+
describe '#print_to_file' do
|
31
31
|
|
32
|
-
subject { Klipbook::
|
32
|
+
subject { Klipbook::PrettyPrint::HtmlPrinter.new(message_stream).print_to_file(book, @output_dir, force) }
|
33
33
|
|
34
34
|
let(:force) { false }
|
35
35
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Klipbook::
|
3
|
+
describe Klipbook::Sources::BookSource do
|
4
4
|
|
5
5
|
let(:fake_source) do
|
6
6
|
Object.new.tap do |fakey|
|
@@ -10,14 +10,14 @@ describe Klipbook::Fetcher do
|
|
10
10
|
|
11
11
|
context 'when created with an invalid source' do
|
12
12
|
it 'raises an error' do
|
13
|
-
expect { Klipbook::
|
13
|
+
expect { Klipbook::Sources::BookSource.new('sdf' , 2) }.to raise_error(InvalidSourceError)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'when created with a site source' do
|
18
|
-
subject {
|
18
|
+
subject { book_source }
|
19
19
|
|
20
|
-
let(:
|
20
|
+
let(:book_source) { Klipbook::Sources::BookSource.new('site:username@example.com:password', 2) }
|
21
21
|
|
22
22
|
before(:each) do
|
23
23
|
stub(Klipbook::Sources::AmazonSite::SiteScraper).new { fake_source }
|
@@ -28,8 +28,8 @@ describe Klipbook::Fetcher do
|
|
28
28
|
Klipbook::Sources::AmazonSite::SiteScraper.should have_received.new('username@example.com', 'password', 2)
|
29
29
|
end
|
30
30
|
|
31
|
-
describe '#
|
32
|
-
subject {
|
31
|
+
describe '#books' do
|
32
|
+
subject { book_source.books }
|
33
33
|
|
34
34
|
let(:books) { [] }
|
35
35
|
|
@@ -40,9 +40,9 @@ describe Klipbook::Fetcher do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'when created with a file source' do
|
43
|
-
subject {
|
43
|
+
subject { book_source }
|
44
44
|
|
45
|
-
let(:
|
45
|
+
let(:book_source) { Klipbook::Sources::BookSource.new('file:filename', 2) }
|
46
46
|
|
47
47
|
let(:fake_file) do
|
48
48
|
Object.new.tap do |file|
|
@@ -62,18 +62,18 @@ describe Klipbook::Fetcher do
|
|
62
62
|
File.should have_received.open('filename', 'r')
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
pending 'uses the file contents to create a file source' do
|
66
66
|
subject
|
67
67
|
|
68
68
|
Klipbook::Sources::KindleDevice::File.should have_received.new('fake contents', 2)
|
69
69
|
end
|
70
70
|
|
71
|
-
describe '#
|
72
|
-
subject {
|
71
|
+
describe '#books' do
|
72
|
+
subject { book_source.books }
|
73
73
|
|
74
74
|
let(:books) { [] }
|
75
75
|
|
76
|
-
|
76
|
+
pending 'returns the books returned by the file source' do
|
77
77
|
subject.should == books
|
78
78
|
end
|
79
79
|
end
|