klipbook 2.1.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.txt +11 -0
- data/Gemfile +2 -15
- data/Gemfile.lock +73 -113
- data/LICENSE.txt +18 -17
- data/README.md +63 -69
- data/Rakefile +3 -30
- data/bin/klipbook +3 -221
- data/klipbook.gemspec +32 -118
- data/lib/klipbook/cli.rb +69 -0
- data/lib/klipbook/commands/command.rb +39 -0
- data/lib/klipbook/commands/export.rb +50 -0
- data/lib/klipbook/commands/exporters/exporter.rb +49 -0
- data/lib/klipbook/{tohtml → commands/exporters}/html_book_summary.erb +1 -1
- data/lib/klipbook/commands/exporters/html_exporter.rb +25 -0
- data/lib/klipbook/commands/exporters/json_exporter.rb +17 -0
- data/lib/klipbook/commands/exporters/markdown_book_summary.erb +12 -0
- data/lib/klipbook/commands/exporters/markdown_exporter.rb +19 -0
- data/lib/klipbook/commands/list.rb +17 -0
- data/lib/klipbook/config.rb +18 -10
- data/lib/klipbook/logger.rb +15 -0
- data/lib/klipbook/sources/amazon_site/book_scraper.rb +0 -2
- data/lib/klipbook/sources/book.rb +36 -21
- data/lib/klipbook/sources/clipping.rb +10 -8
- data/lib/klipbook/sources/kindle_device/entry.rb +8 -6
- data/lib/klipbook/sources/kindle_device/entry_parser.rb +66 -64
- data/lib/klipbook/sources/kindle_device/file.rb +45 -43
- data/lib/klipbook/sources/kindle_device/file_parser.rb +23 -21
- data/lib/klipbook/sources/source.rb +30 -0
- data/lib/klipbook/version.rb +1 -1
- data/lib/klipbook.rb +11 -11
- metadata +56 -113
- data/.document +0 -5
- data/.yardopts +0 -1
- data/Guardfile +0 -19
- data/features/fixtures/clippings-for-three-books.txt +0 -105
- data/features/list.feature +0 -31
- data/features/step_definitions/list_steps.rb +0 -15
- data/features/step_definitions/tohtml_steps.rb +0 -61
- data/features/step_definitions/tojson_steps.rb +0 -17
- data/features/support/env.rb +0 -16
- data/features/tohtml.feature +0 -51
- data/features/tojson.feature +0 -11
- data/lib/klipbook/colours.rb +0 -16
- data/lib/klipbook/commands/list_books.rb +0 -19
- data/lib/klipbook/commands/tohtml.rb +0 -17
- data/lib/klipbook/commands/tojson.rb +0 -18
- data/lib/klipbook/sources/invalid_source_error.rb +0 -12
- data/lib/klipbook/tohtml/html_printer.rb +0 -39
- data/lib/klipbook/tojson/book_file.rb +0 -58
- data/spec/lib/klipbook/commands/list_books_spec.rb +0 -43
- data/spec/lib/klipbook/commands/tohtml_spec.rb +0 -36
- data/spec/lib/klipbook/sources/book_spec.rb +0 -33
- data/spec/lib/klipbook/sources/kindle_device/entry_parser_spec.rb +0 -339
- data/spec/lib/klipbook/sources/kindle_device/file_parser_spec.rb +0 -68
- data/spec/lib/klipbook/sources/kindle_device/file_spec.rb +0 -163
- data/spec/lib/klipbook/tohtml/html_printer_spec.rb +0 -88
- data/spec/lib/klipbook/tojson/book_file_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -7
@@ -1,163 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Klipbook::Sources::KindleDevice::File do
|
4
|
-
|
5
|
-
let(:file) { Klipbook::Sources::KindleDevice::File.new(input_file, max_books, file_parser) }
|
6
|
-
|
7
|
-
let(:max_books) { 30 }
|
8
|
-
|
9
|
-
let(:entries) { [] }
|
10
|
-
|
11
|
-
let(:file_parser) { double(extract_entries: entries) }
|
12
|
-
|
13
|
-
let(:input_file) { double(read: 'file text') }
|
14
|
-
|
15
|
-
describe '#books' do
|
16
|
-
subject { file.books }
|
17
|
-
|
18
|
-
it 'parses the file text with the file parser' do
|
19
|
-
subject
|
20
|
-
expect(file_parser).to have_received(:extract_entries).with('file text')
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'with entries for three books' do
|
24
|
-
let(:entries) do
|
25
|
-
[
|
26
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
27
|
-
e.title = 'Book one'
|
28
|
-
e.author = 'Author one'
|
29
|
-
e.type = :highlight
|
30
|
-
e.added_on = DateTime.new(2012, 10, 10)
|
31
|
-
end,
|
32
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
33
|
-
e.title = 'Book one'
|
34
|
-
e.author = 'Author one'
|
35
|
-
e.type = :highlight
|
36
|
-
e.added_on = DateTime.new(2012, 10, 10)
|
37
|
-
end,
|
38
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
39
|
-
e.title = 'Book two'
|
40
|
-
e.author = 'Author two'
|
41
|
-
e.type = :highlight
|
42
|
-
e.added_on = DateTime.new(2012, 10, 12)
|
43
|
-
end,
|
44
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
45
|
-
e.title = 'Book three'
|
46
|
-
e.author = 'Author two'
|
47
|
-
e.type = :highlight
|
48
|
-
e.added_on = DateTime.new(2012, 10, 11)
|
49
|
-
end
|
50
|
-
]
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'returns three books' do
|
54
|
-
expect(subject.size).to eq 3
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'returns books sorted by last_update descending' do
|
58
|
-
expect(subject.map(&:title)).to eq [ 'Book two', 'Book three', 'Book one' ]
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'and max_books set to 2' do
|
62
|
-
|
63
|
-
let (:max_books) { 2 }
|
64
|
-
|
65
|
-
it 'returns two books' do
|
66
|
-
expect(subject.size).to eq 2
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'with entries for a single book' do
|
72
|
-
let(:entries) do
|
73
|
-
[
|
74
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
75
|
-
e.title = 'Book one'
|
76
|
-
e.author = 'Author one'
|
77
|
-
e.type = :bookmark
|
78
|
-
e.location = 1
|
79
|
-
e.page = 1
|
80
|
-
e.added_on = DateTime.new(2012, 10, 10)
|
81
|
-
e.text = 'First one'
|
82
|
-
end,
|
83
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
84
|
-
e.title = 'Book one'
|
85
|
-
e.author = 'Author one'
|
86
|
-
e.type = :highlight
|
87
|
-
e.location = 10
|
88
|
-
e.page = 3
|
89
|
-
e.added_on = DateTime.new(2012, 10, 11)
|
90
|
-
e.text = 'Second one'
|
91
|
-
end,
|
92
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
93
|
-
e.title = 'Book one'
|
94
|
-
e.author = 'Author one'
|
95
|
-
e.type = :highlight
|
96
|
-
e.location = 3
|
97
|
-
e.page = 2
|
98
|
-
e.added_on = DateTime.new(2012, 10, 1)
|
99
|
-
e.text = 'Third one'
|
100
|
-
end,
|
101
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
102
|
-
e.title = 'Book one'
|
103
|
-
e.author = 'Author one'
|
104
|
-
e.type = :note
|
105
|
-
e.location = 2
|
106
|
-
e.page = 1
|
107
|
-
e.added_on = DateTime.new(2012, 10, 21)
|
108
|
-
e.text = 'Fourth one'
|
109
|
-
end
|
110
|
-
]
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'returns a single book with the correct title and author information' do
|
114
|
-
expect(subject.first.title).to eq 'Book one'
|
115
|
-
expect(subject.first.author).to eq 'Author one'
|
116
|
-
end
|
117
|
-
|
118
|
-
it "returns a single book with last update equal to the latest added on date of the book's entries" do
|
119
|
-
expect(subject.first.last_update).to eq DateTime.new(2012, 10, 21)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "ignores bookmarks when building the book's clipping list" do
|
123
|
-
expect(subject.first.clippings.size).to eq 3
|
124
|
-
expect(subject.first.clippings.map(&:type)).not_to include(:bookmark)
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'returns a single book whose clippings are sorted by location' do
|
128
|
-
expect(subject.first.clippings.map(&:location)).to eq [2, 3, 10]
|
129
|
-
expect(subject.first.clippings.map(&:text)).to eq ['Fourth one', 'Third one', 'Second one']
|
130
|
-
expect(subject.first.clippings.map(&:page)).to eq [1, 2, 3]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'with entries for a single book that are all bookmarks' do
|
135
|
-
let(:entries) do
|
136
|
-
[
|
137
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
138
|
-
e.title = 'Book one'
|
139
|
-
e.author = 'Author one'
|
140
|
-
e.type = :bookmark
|
141
|
-
e.location = 1
|
142
|
-
e.page = 1
|
143
|
-
e.added_on = DateTime.new(2012, 10, 10)
|
144
|
-
e.text = 'First one'
|
145
|
-
end,
|
146
|
-
Klipbook::Sources::KindleDevice::Entry.new do |e|
|
147
|
-
e.title = 'Book one'
|
148
|
-
e.author = 'Author one'
|
149
|
-
e.type = :bookmark
|
150
|
-
e.location = 10
|
151
|
-
e.page = 3
|
152
|
-
e.added_on = DateTime.new(2012, 10, 11)
|
153
|
-
e.text = 'Second one'
|
154
|
-
end
|
155
|
-
]
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'should be empty' do
|
159
|
-
expect(subject).to be_empty
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# This is more of an integration test but what the heck
|
4
|
-
# it can live in here for now
|
5
|
-
|
6
|
-
describe Klipbook::ToHtml::HtmlPrinter do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
@output_dir = Dir.mktmpdir
|
10
|
-
end
|
11
|
-
|
12
|
-
after(:all) do
|
13
|
-
FileUtils.rm_f(@output_dir)
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:book) do
|
17
|
-
Klipbook::Book.new.tap do |b|
|
18
|
-
b.title = 'Fake book title'
|
19
|
-
b.author = 'Fake Author'
|
20
|
-
b.clippings = []
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:message_stream) do
|
25
|
-
double(puts: nil)
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#print_to_file' do
|
29
|
-
|
30
|
-
subject { Klipbook::ToHtml::HtmlPrinter.new(message_stream).print_to_file(book, @output_dir, force) }
|
31
|
-
|
32
|
-
let(:force) { false }
|
33
|
-
|
34
|
-
let(:expected_filename) { "Fake book title by Fake Author.html" }
|
35
|
-
let(:expected_filepath) { "#{@output_dir}/Fake book title by Fake Author.html" }
|
36
|
-
|
37
|
-
context 'with no existing summary file' do
|
38
|
-
before(:each) do
|
39
|
-
FileUtils.rm_f(File.join(@output_dir, '*'))
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'writes a file named after the book into the output directory' do
|
43
|
-
subject
|
44
|
-
expect(File.exists?(expected_filepath)).to be_truthy
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'writes a html summary to the file' do
|
48
|
-
subject
|
49
|
-
expect(File.read(expected_filepath)).to include("<h1>Fake book title</h1>")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with an existing summary file' do
|
54
|
-
before(:each) do
|
55
|
-
FileUtils.rm_f(expected_filepath)
|
56
|
-
FileUtils.touch(expected_filepath)
|
57
|
-
end
|
58
|
-
|
59
|
-
context "and 'force' set to false" do
|
60
|
-
let(:force) { false }
|
61
|
-
|
62
|
-
it "won't write to the file" do
|
63
|
-
subject
|
64
|
-
expect(File.size(expected_filepath)).to eq 0
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'prints a message informing that the file is being skipped' do
|
68
|
-
subject
|
69
|
-
expect(message_stream).to have_received(:puts).with("\e[33mSkipping \e[0m#{expected_filename}")
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "and 'force' set to true" do
|
74
|
-
let(:force) { true }
|
75
|
-
|
76
|
-
it 'overwrites the file' do
|
77
|
-
subject
|
78
|
-
expect(File.size(expected_filepath)).to be > 0
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'prints a message informing that the file is being written' do
|
82
|
-
subject
|
83
|
-
expect(message_stream).to have_received(:puts).with("\e[32mWriting \e[0m#{expected_filename}")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Klipbook::ToJson::BookFile do
|
4
|
-
|
5
|
-
describe '.from_json' do
|
6
|
-
|
7
|
-
subject { Klipbook::ToJson::BookFile.from_json(json) }
|
8
|
-
|
9
|
-
context 'with empty json' do
|
10
|
-
|
11
|
-
let(:json) { '' }
|
12
|
-
|
13
|
-
it 'returns an object with no books' do
|
14
|
-
expect(subject.books).to be_empty
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#add_books' do
|
20
|
-
let (:message_stream) do
|
21
|
-
double(puts: nil)
|
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::ToJson::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
|
-
|
46
|
-
expect(it.books.size).to eq 3
|
47
|
-
expect(it.books).to include(new_book)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "replaces books that exist if force is true" do
|
51
|
-
new_book = Klipbook::Book.new.tap do |b|
|
52
|
-
b.title = 'Book one'
|
53
|
-
b.author = 'Author one'
|
54
|
-
b.asin = 'new asin'
|
55
|
-
end
|
56
|
-
|
57
|
-
it.add_books([ new_book ], true, message_stream)
|
58
|
-
|
59
|
-
expect(it.books.size).to eq 2
|
60
|
-
expect(it.books).to include(new_book)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "does not replace existing books if force is false" do
|
64
|
-
new_book = Klipbook::Book.new.tap do |b|
|
65
|
-
b.title = 'Book one'
|
66
|
-
b.author = 'Author one'
|
67
|
-
b.asin = 'new asin'
|
68
|
-
end
|
69
|
-
|
70
|
-
it.add_books([ new_book ], false, message_stream)
|
71
|
-
|
72
|
-
expect(it.books.size).to eq 2
|
73
|
-
expect(it.books).not_to include(new_book)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|