booklist 0.0.7 → 0.0.9
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +0 -1
- data/bin/booklist +122 -178
- data/booklist.gemspec +2 -2
- data/lib/booklist/version.rb +1 -1
- data/lib/booklist.rb +68 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9563af51bd960512923c640e4d09d280703dcc78
|
4
|
+
data.tar.gz: ec4cfca402e541297d083911f8ab966df32247df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31294702b7174bcc5cb7a6a5f0917c8b1a6ed8ed7d59bf28314d46975f63e1f1c01d661b153d9fda20caa27a901e46fdce9b49e3534544a8d7924328cb521d31
|
7
|
+
data.tar.gz: 385d1e7333062b05f40ddc174f7e050174e02c13481bdfd1752d00b6d6102579be7eab627f6132358d7dcae0ab3096f46d5d50255fe6511d047c17a40768aca7
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
booklist*gem
|
data/Gemfile
CHANGED
data/bin/booklist
CHANGED
@@ -32,188 +32,132 @@ require 'pathname'
|
|
32
32
|
require 'booklist'
|
33
33
|
require 'date'
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
opts.on("--updatedb", "Update the book database schema") do
|
121
|
-
options.update_schema = true
|
122
|
-
end
|
123
|
-
|
124
|
-
opts.on_tail("--version", "Get the booklist version") do
|
125
|
-
puts Booklist::VERSION
|
126
|
-
exit
|
127
|
-
end
|
128
|
-
|
129
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
130
|
-
puts opts
|
131
|
-
exit
|
132
|
-
end
|
133
|
-
|
134
|
-
usage = opts
|
135
|
-
end.parse!
|
136
|
-
|
137
|
-
if options.act_num > 1
|
138
|
-
puts "Please only use one action."
|
139
|
-
puts usage
|
35
|
+
options = OpenStruct.new
|
36
|
+
options.action = nil
|
37
|
+
usage = nil
|
38
|
+
OptionParser.new do |opts|
|
39
|
+
opts.banner = "Usage: booklist [options]"
|
40
|
+
|
41
|
+
opts.separator "Actions:"
|
42
|
+
opts.on("-a", "--add", "Add a book record", "(--title is required)") do
|
43
|
+
options.action = :add
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on("-e", "--edit [ID]", Integer, "Edit a book record") do |id|
|
47
|
+
options.id = id if id
|
48
|
+
options.action = :edit
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("-d", "--delete [ID]", Integer, "Delete a book record") do |id|
|
52
|
+
options.id = id if id
|
53
|
+
options.action = :delete
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on("-s", "--search", "Search for a book") do
|
57
|
+
options.action = :search
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on("-r", "--read [ID]", Integer, "Show a book record's details") do |id|
|
61
|
+
options.id = id if id
|
62
|
+
options.action = :read
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on("--list", "List all books in the database") do
|
66
|
+
options.action = :list
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.separator ""
|
70
|
+
opts.separator "Book details:"
|
71
|
+
|
72
|
+
# Book details
|
73
|
+
opts.on("--title TITLE", "Book title") do |title|
|
74
|
+
options.title = title
|
75
|
+
end
|
76
|
+
|
77
|
+
opts.on("--state STATE", "What state the book is in (read, to-read, reading, abandoned)") do |state|
|
78
|
+
options.state = state
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on("--author AUTHOR", "Book author") do |author|
|
82
|
+
options.author = author
|
83
|
+
end
|
84
|
+
|
85
|
+
opts.on("--addn_authors ADDN_AUTHORS", "Additional authors") do |aa|
|
86
|
+
options.addn_authors = aa
|
87
|
+
end
|
88
|
+
|
89
|
+
opts.on("--tags X,Y,Z", Array, "List of tags") do |tags|
|
90
|
+
options.tags = tags
|
91
|
+
end
|
92
|
+
|
93
|
+
opts.on("--date_read DATE", Date, "Date read (eg 2014-02-14)") do |dr|
|
94
|
+
options.date_read = dr
|
95
|
+
end
|
96
|
+
|
97
|
+
opts.on("--id ID", Integer, "Book ID number") do |id|
|
98
|
+
options.id = id
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.separator ""
|
102
|
+
opts.separator "Common options:"
|
103
|
+
|
104
|
+
# TODO - configurable booklist path
|
105
|
+
#opts.on("-c", "--config FILE", "Use configuration file") do |file|
|
106
|
+
# options.config_file = file
|
107
|
+
#end
|
108
|
+
|
109
|
+
opts.on("--debug", "Debug mode") do
|
110
|
+
options.debug = true
|
111
|
+
end
|
112
|
+
|
113
|
+
opts.on("--updatedb", "Update the book database schema") do
|
114
|
+
options.update_schema = true
|
115
|
+
end
|
116
|
+
|
117
|
+
opts.on_tail("--version", "Get the booklist version") do
|
118
|
+
puts Booklist::VERSION
|
140
119
|
exit
|
141
120
|
end
|
142
121
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
# TODO configurable booklist path
|
147
|
-
booklist_db_path = File.join(Dir.home, '.booklist', 'booklist.db')
|
148
|
-
|
149
|
-
ActiveRecord::Base.establish_connection(
|
150
|
-
:adapter => 'sqlite3',
|
151
|
-
:database => booklist_db_path.to_s)
|
152
|
-
ActiveRecord::Base.logger = Logger.new(STDERR) if options.debug
|
153
|
-
|
154
|
-
if options.update_schema || !File.exist?(booklist_db_path)
|
155
|
-
ActiveRecord::Migrator.migrate('db/migrate')
|
156
|
-
end
|
157
|
-
|
158
|
-
if options.act_num = 1
|
159
|
-
if options.action == :add
|
160
|
-
if !options.title || options.title == ""
|
161
|
-
puts "Please add a --title with the book name"
|
162
|
-
puts usage
|
163
|
-
exit
|
164
|
-
end
|
165
|
-
book = Book.new do |b|
|
166
|
-
b.title = options.title
|
167
|
-
b.author = options.author if options.author
|
168
|
-
b.addn_authors = options.addn_authors if options.addn_authors
|
169
|
-
b.state = options.state if options.state
|
170
|
-
b.date_read = options.date_read if options.date_read
|
171
|
-
b.tag_list = options.tags if options.tags
|
172
|
-
end
|
173
|
-
book.save
|
174
|
-
book.cli_display
|
175
|
-
elsif options.action == :edit
|
176
|
-
book = Book.find_by(id: options.id)
|
177
|
-
if book
|
178
|
-
book.title = options.title if options.title
|
179
|
-
book.author = options.author if options.author
|
180
|
-
book.addn_authors = options.addn_authors if options.addn_authors
|
181
|
-
book.state = options.state if options.state
|
182
|
-
book.date_read = options.date_read if options.date_read
|
183
|
-
book.tag_list = options.tags if options.tags
|
184
|
-
book.save
|
185
|
-
book.cli_display
|
186
|
-
else
|
187
|
-
puts "No book with ID of #{options.id} was found"
|
188
|
-
end
|
189
|
-
elsif options.action == :delete
|
190
|
-
book = Book.find_by(id: options.id)
|
191
|
-
book.destroy
|
192
|
-
elsif options.action == :read
|
193
|
-
book = Book.find_by(id: options.id)
|
194
|
-
if book
|
195
|
-
book.cli_display
|
196
|
-
else
|
197
|
-
puts "No book with ID of #{options.id} was found"
|
198
|
-
end
|
199
|
-
elsif options.action == :search
|
200
|
-
books = []
|
201
|
-
books += Book.where(["title LIKE ?", "%#{options.title}%"]).to_a if options.title
|
202
|
-
books += Book.where(["author LIKE ? or addn_authors LIKE ?", "%#{options.author}%", "%#{options.author}%"]).to_a if options.author
|
203
|
-
books += Book.where(["author LIKE ? or addn_authors LIKE ?", "%#{options.addn_authors}%", "%#{options.addn_authors}%"]).to_a if options.addn_authors
|
204
|
-
books += Book.where(["state = ?", "%#{options.state}%"]).to_a if options.state
|
205
|
-
books.uniq!
|
206
|
-
books.sort!{ |a, b| a.id <=> b.id}
|
207
|
-
books.select!{ |b| b.state == options.state} if options.state
|
208
|
-
books.each { |b| b.cli_display }
|
209
|
-
elsif options.action == :list
|
210
|
-
books = Book.all
|
211
|
-
books.each{ |b| b.cli_display }
|
212
|
-
end
|
213
|
-
elsif options.act_num > 1
|
214
|
-
puts "Please only use one action."
|
215
|
-
puts usage
|
122
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
123
|
+
puts opts
|
216
124
|
exit
|
217
125
|
end
|
218
126
|
|
127
|
+
usage = opts
|
128
|
+
end.parse!
|
129
|
+
|
130
|
+
unless options.action
|
131
|
+
puts "No action specified"
|
132
|
+
puts usage
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
|
136
|
+
# TODO Create configuration directory if it doesn't exist
|
137
|
+
# mkdir ~/.booklist
|
138
|
+
|
139
|
+
# TODO configurable booklist path
|
140
|
+
booklist_db_path = File.join(Dir.home, '.booklist', 'booklist.db')
|
141
|
+
|
142
|
+
ActiveRecord::Base.establish_connection(
|
143
|
+
:adapter => 'sqlite3',
|
144
|
+
:database => booklist_db_path.to_s)
|
145
|
+
ActiveRecord::Base.logger = Logger.new(STDERR) if options.debug
|
146
|
+
|
147
|
+
if options.update_schema || !File.exist?(booklist_db_path)
|
148
|
+
ActiveRecord::Migrator.migrate('db/migrate')
|
149
|
+
end
|
150
|
+
|
151
|
+
if options.action == :add
|
152
|
+
Booklist::add_book(options)
|
153
|
+
elsif options.action == :edit
|
154
|
+
Booklist::edit_book(options)
|
155
|
+
elsif options.action == :delete
|
156
|
+
Booklist::delete_book(options.id)
|
157
|
+
elsif options.action == :read
|
158
|
+
Booklist::read_book(options.id)
|
159
|
+
elsif options.action == :search
|
160
|
+
Booklist::search_books(options)
|
161
|
+
elsif options.action == :list
|
162
|
+
Booklist.list_books
|
219
163
|
end
|
data/booklist.gemspec
CHANGED
@@ -3,11 +3,11 @@ require File.expand_path('../lib/booklist/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = "booklist"
|
6
|
-
gem.authors = ["
|
6
|
+
gem.authors = ["David Crosby"]
|
7
7
|
gem.description = %q{A book collection program}
|
8
8
|
gem.summary = %q{Booklist helps you keep a list of books you've read or want to read.}
|
9
9
|
|
10
|
-
gem.email = "
|
10
|
+
gem.email = "dave@dafyddcrosby.com"
|
11
11
|
gem.homepage = "https://github.com/dafyddcrosby/booklist"
|
12
12
|
|
13
13
|
gem.license = 'bsd' # The (three-clause) BSD License
|
data/lib/booklist/version.rb
CHANGED
data/lib/booklist.rb
CHANGED
@@ -1,3 +1,71 @@
|
|
1
1
|
require 'booklist/version'
|
2
2
|
require 'booklist/book'
|
3
3
|
require 'booklist/tag'
|
4
|
+
|
5
|
+
module Booklist
|
6
|
+
def self.add_book(options)
|
7
|
+
if !options.title || options.title == ""
|
8
|
+
puts "Please add a --title with the book name"
|
9
|
+
puts usage
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
book = Book.new do |b|
|
13
|
+
b.title = options.title
|
14
|
+
b.author = options.author if options.author
|
15
|
+
b.addn_authors = options.addn_authors if options.addn_authors
|
16
|
+
b.state = options.state if options.state
|
17
|
+
b.date_read = options.date_read if options.date_read
|
18
|
+
b.tag_list = options.tags if options.tags
|
19
|
+
end
|
20
|
+
book.save
|
21
|
+
book.cli_display
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.edit_book(options)
|
25
|
+
book = Book.find_by(id: options.id)
|
26
|
+
if book
|
27
|
+
book.title = options.title if options.title
|
28
|
+
book.author = options.author if options.author
|
29
|
+
book.addn_authors = options.addn_authors if options.addn_authors
|
30
|
+
book.state = options.state if options.state
|
31
|
+
book.date_read = options.date_read if options.date_read
|
32
|
+
book.tag_list = options.tags if options.tags
|
33
|
+
book.save
|
34
|
+
book.cli_display
|
35
|
+
else
|
36
|
+
puts "No book with ID of #{options.id} was found"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.read_book(id)
|
41
|
+
book = Book.find_by(id: id)
|
42
|
+
if book
|
43
|
+
book.cli_display
|
44
|
+
else
|
45
|
+
puts "No book with ID of #{id} was found"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.search_books(options)
|
50
|
+
books = []
|
51
|
+
books += Book.where(["title LIKE ?", "%#{options.title}%"]).to_a if options.title
|
52
|
+
books += Book.where(["author LIKE ? or addn_authors LIKE ?", "%#{options.author}%", "%#{options.author}%"]).to_a if options.author
|
53
|
+
books += Book.where(["author LIKE ? or addn_authors LIKE ?", "%#{options.addn_authors}%", "%#{options.addn_authors}%"]).to_a if options.addn_authors
|
54
|
+
books += Book.where(["state = ?", "%#{options.state}%"]).to_a if options.state
|
55
|
+
books.uniq!
|
56
|
+
books.sort!{ |a, b| a.id <=> b.id}
|
57
|
+
books.select!{ |b| b.state == options.state} if options.state
|
58
|
+
books.each { |b| b.cli_display }
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.delete_book(id)
|
62
|
+
book = Book.find_by(id: id)
|
63
|
+
book.destroy
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.list_books
|
67
|
+
books =Book.all
|
68
|
+
books.each{ |b| b.cli_display }
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booklist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- David Crosby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -53,12 +53,13 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: A book collection program
|
56
|
-
email:
|
56
|
+
email: dave@dafyddcrosby.com
|
57
57
|
executables:
|
58
58
|
- booklist
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- .gitignore
|
62
63
|
- Gemfile
|
63
64
|
- LICENSE
|
64
65
|
- README.md
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
94
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.1.11
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Booklist helps you keep a list of books you've read or want to read.
|