glibrary 0.0.0 → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ebb0b283f8a02d344327ef0ddb6bb19bfb5e180aecb45403a21a08e182fc42b
4
- data.tar.gz: a388772cb5f7b81ff05d08efd9ebbdde68114040076054a76268ad6ea879ea72
3
+ metadata.gz: 51bec53849f1ea68333a878d0ca2f1a8733aab8d75d727f61831926aec01144e
4
+ data.tar.gz: 2478df4c25c3b8044e274ff4fa9abfea269f0ff84b9e4a419808bae77d7f4088
5
5
  SHA512:
6
- metadata.gz: d305157edaf5fe228fc2c7134359d15057b8086404899619400177c06900dc0edd389ef1b3fc11c48dfb459f1c99f86079cb25a5ef718a8633cfb0d26738e566
7
- data.tar.gz: 9bd4b1599e77b79ce5f4563776ad15ff1f0a01f93058ec4d20907de61aaf40de11d1c4b1b5c1fb98c125c81902fc72cef44ee32bd143441936b80c0d75a505eb
6
+ metadata.gz: fd7ca5dac37e99be6016f2e9a37ea2203f33e1b17370c2411dcc15c6f67cc1d0c8acb7427e43b220f0b4ad3f8e450bd6630d15d576c1c411b8b09e902b0ed74c
7
+ data.tar.gz: 401f7b4f588ae8d5d65c4c562acd12073242ccd2673367eafe9e6ad4428af17f97985baf4b15613bdf36f49e7d30cfd2abe3209945f8a3d4fac37394bdc54ccb
data/bin/glibrary CHANGED
@@ -16,7 +16,7 @@ ARGV << '-h' if ARGV.empty?
16
16
  ARGV << ARGV.delete("-l") if ARGV.include?("-l")
17
17
 
18
18
  #default filename for saved reading list
19
- filename = File.dirname(File.expand_path(__FILE__)) + "/saved_libraries/library.json"
19
+ filename = File.join(File.dirname(__FILE__), "../saved_libraries/library.json")
20
20
 
21
21
  #initialize the hash which will hold the search parameters
22
22
  o = {}
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glibrary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Engelbert
@@ -25,7 +25,7 @@ files:
25
25
  - common/errors.rb
26
26
  - common/google_api_url.rb
27
27
  - common/search_error.rb
28
- - glibrary.rb
28
+ - saved_libraries/.gitkeep
29
29
  homepage: https://github.com/pmengelbert/g_library
30
30
  licenses:
31
31
  - MIT
@@ -33,7 +33,9 @@ metadata: {}
33
33
  post_install_message:
34
34
  rdoc_options: []
35
35
  require_paths:
36
- - lib
36
+ - common
37
+ - saved_libraries
38
+ - classes
37
39
  required_ruby_version: !ruby/object:Gem::Requirement
38
40
  requirements:
39
41
  - - ">="
data/glibrary.rb DELETED
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'json'
3
- require 'optparse'
4
- require 'io/console'
5
-
6
- require_relative 'common/api_query'
7
- require_relative 'common/google_api_url'
8
- require_relative 'classes/book_search'
9
- require_relative 'classes/user_book'
10
- require_relative 'classes/user_library'
11
- require_relative 'common/errors'
12
-
13
- ARGV << '-h' if ARGV.empty?
14
-
15
- #make sure the -l flag is process *after* the -f flag, by putting it at the end
16
- ARGV << ARGV.delete("-l") if ARGV.include?("-l")
17
-
18
- #default filename for saved reading list
19
- filename = File.dirname(File.expand_path(__FILE__)) + "/saved_libraries/library.json"
20
-
21
- #initialize the hash which will hold the search parameters
22
- o = {}
23
-
24
- #parse the command-line options
25
- OptionParser.new do |opts|
26
- opts.banner = "Usage: ruby g_library.rb [options...] [query]"
27
- #sets 'library-mode'
28
- library = opts.default_argv.include?("-l")
29
-
30
- opts.on("-t", "--title=TITLE", "Specify a title keyword") do |t|
31
- o[:title] = t
32
- end
33
-
34
- opts.on("-a", "--author=AUTHOR", "Specify an author keyword") do |a|
35
- o[:author] = a
36
- end
37
-
38
- opts.on("-p", "--publisher=PUBLISHER", "Specify a publisher keyword") do |p|
39
- o[:publisher] = p
40
- end
41
-
42
- opts.on("-f", "--lib-file=LIBFILE", "Select a library save file") do |libfile|
43
- filename = File.absolute_path(libfile)
44
- unless File.exist?(filename)
45
- (puts "Library file not found, cannot display."; exit) if library
46
- puts "Creating new file"
47
- end
48
- end
49
-
50
- opts.on("-l", "--library", "See your library; ignores all search options
51
- \t\t\t\t\tdefault library file is [repository_root]/saved_libraries/library.json") do
52
-
53
- #substitute \ for / if the machine is running windows
54
- filename.gsub!(/\//, '\\') if ENV.values.any? { |v| v =~ /[A-Z]:\\Windows/i }
55
-
56
-
57
- #print out the library and exit the program
58
- l = UserLibrary.new(filename)
59
- l.pretty_print
60
- exit
61
- end
62
-
63
- opts.on("-h", "--help", "Prints this help") do
64
- puts ""
65
- puts opts
66
- puts "[query]: all other arguments will be treated as general search keywords"
67
- puts ""
68
- exit
69
- end
70
-
71
- end.parse!
72
-
73
- #substitute \ for / if the machine is running windows
74
- filename.gsub!(/\//, '\\') if ENV.values.any? { |v| v =~ /C:\\Windows/i }
75
-
76
- # Create or load the library, depending on whether or not the file already exists.
77
- l = UserLibrary.new(filename)
78
-
79
- #initialize the
80
- #perform the search, and display the results.
81
- begin
82
- s = BookSearch.new(search: ARGV.join('+'), title: o[:title], author: o[:author], publisher: o[:publisher])
83
-
84
- #see BookSearch definition in classes/book_search.rb
85
- #the each method (and all Enumerable methods, like map) only operate on
86
- #the first five matches.
87
- books = s.map { |info| UserBook.new(info) }
88
-
89
- #print the resuls
90
- puts ""
91
- books.each_with_index do |b, i|
92
- keys = %w[title author publisher]
93
- n = i+1
94
- puts "-"*5 + "Match ##{n}" + "-"*5
95
- keys.each do |k|
96
- puts "%s: %s" % [k.capitalize, b[k]]
97
- end
98
- puts ""
99
- end
100
-
101
- print "Enter a number (1-5) to add a book to your reading list:\n(or any other key to quit)\n"
102
-
103
- selection = STDIN.getch.chomp.to_i
104
- i = selection - 1
105
- puts ""
106
- exit if i < 0 or i > 4
107
-
108
- #add a book to the user's library
109
- l << books[i]
110
- l.save
111
-
112
- rescue SearchError
113
- puts "\nThere was an error with your query; be careful to format it well"
114
- puts ""
115
- exit
116
- rescue NoResults
117
- puts "\nNo results."
118
- puts ""
119
- exit
120
- end