franklin 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b7efde29c026dbc795cbe81417a627ef35ca556
4
- data.tar.gz: 71cc18d43c0e669942f9133e2326ee66b3060279
3
+ metadata.gz: a7bee880c35d71a839754345afcad98f0cc58ce3
4
+ data.tar.gz: bbda755d21be8278a41cce095f786a1015c05389
5
5
  SHA512:
6
- metadata.gz: 46bd872e98f7190a6e3cf69bffad1acbd49e816a2ea58e1f8e51d681b850030aa92c4702f26c59fb90f87098208f8f1b504437e7f07d243a463b3d8656501bb2
7
- data.tar.gz: 2788cc2a039330ea05d811028266d67754d3dc9d306f1b0570a96c9d003ce38781d14c0052462629c6a89152d0603c1ebdf5d60d85fc4330e4b25824e3802fa9
6
+ metadata.gz: 507396aba4b52f6a973a78731bb071453d102f94aa10ba3c1c1d382fc8ef714d93f5095cdedadfe02aa4f286010d038b77e8b0d213f6f18f39f53c1294e00574
7
+ data.tar.gz: 4d13e4c433b4478bc437d83e2d36e3f781522c6befcc7ec0e0da2fcb33d0f8381bfe68587922b2f2f3128257f6cba97614e1ff145088974e083d3dd006c4e77f
data/README.md CHANGED
@@ -19,9 +19,10 @@ Franklin needs to be configured with information about the Overdrive libraries i
19
19
  :url: http://sfpl.lib.overdrive.com
20
20
  - :name: San Diego Public Library
21
21
  :url: http://sdpl.lib.overdrive.com
22
+ :default_type: eBook # Optional, will show all types if not set.
22
23
  ```
23
24
 
24
- There needs to be a minimum of one library, but there is no maximum. The `name` can be anything and will be included when the search results are presented. The `url` should point to the domain of the public library. It can be obtained by visiting Overdrive's site for each library, copying the url and striping everything after the domain name.
25
+ There needs to be a minimum of one library, but there is no maximum. The `name` can be anything and will be included when the search results are presented. The `url` should point to the domain of the public library. It can be obtained by visiting Overdrive's site for each library, copying the url and stripping everything after the domain name.
25
26
 
26
27
  ## Usage
27
28
 
@@ -69,6 +70,10 @@ Availability:
69
70
  Available @ San Diego County Library
70
71
  ```
71
72
 
73
+ Franklin supports using a different path for the configuration file and filtering results by type (ie, eBook, Audiobook, etc).
74
+
75
+ See `franklin --help` for more information.
76
+
72
77
  ## Development
73
78
 
74
79
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/exe/franklin CHANGED
@@ -1,13 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require "franklin"
3
+ require "optparse"
4
+
5
+ options = { out: STDOUT, config_path: Franklin::Config::DEFAULT_CONFIG_FILE }
6
+ parser = OptionParser.new { |opts|
7
+ opts.banner = "Usage: frankling [options] search_term1 search_term2..."
8
+
9
+ opts.on("-h", "--help", "Prints this help") do
10
+ puts opts
11
+ puts "Franklin v#{Franklin::VERSION}"
12
+ exit
13
+ end
14
+
15
+ opts.on("--config-path=CONFIG", "Path to configuration file. Defaults to ~/.franklin") do |config_path|
16
+ options[:config_path] = config_path
17
+ end
18
+
19
+ opts.on "-tTYPE", "--type=TYPE", "Filter results by type (eBook, Audiobook, etc). Will override config" do |type|
20
+ options[:type] = type
21
+ end
22
+ }
23
+
24
+ parser.parse!
4
25
 
5
26
  begin
6
- Franklin.run(nil, ARGV.join(" "), STDOUT)
27
+ Franklin.run(ARGV.join(" "), options)
7
28
  rescue ArgumentError => ex
8
29
  puts <<-ERROR.gsub(/^ /, "")
9
- Oops! #{ex.message}"
10
- Usage: franklin search_term [other_term..]"
30
+ Oops! #{ex.message}
31
+ #{parser}
11
32
  ERROR
12
33
  rescue Errno::ENOENT
13
34
  puts <<-ERROR.gsub(/^ /, "")
@@ -19,5 +40,6 @@ rescue Errno::ENOENT
19
40
  :url: http://sfpl.lib.overdrive.com
20
41
  - :name: San Diego Public Library
21
42
  :url: http://sdpl.lib.overdrive.com
43
+ :default_type: eBook # Optional, leave empty to search for all types
22
44
  ERROR
23
45
  end
@@ -4,12 +4,13 @@ require "yaml"
4
4
  module Franklin
5
5
  class Config
6
6
  DEFAULT_CONFIG_FILE = File.join(Dir.home, ".franklin").freeze
7
- attr_reader :libraries
7
+ attr_reader :libraries, :default_type
8
8
 
9
9
  def initialize(data)
10
10
  @libraries = data.fetch(:libraries).map { |library|
11
11
  Library.new(library.fetch(:name), library.fetch(:url))
12
12
  }
13
+ @default_type = data[:default_type]
13
14
  end
14
15
 
15
16
  class << self
@@ -0,0 +1,16 @@
1
+ module Franklin
2
+ class TypeFilter
3
+ def initialize(type)
4
+ @type = type
5
+ end
6
+
7
+ def perform(results)
8
+ return results unless type
9
+ results.dup.keep_if { |item, _availability| item.format.casecmp(type) == 0 }
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :type
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Franklin
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/franklin.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  require "franklin/version"
2
2
  require "franklin/config"
3
3
  require "franklin/threaded_search"
4
+ require "franklin/type_filter"
4
5
  require "franklin/console_report"
5
6
 
6
7
  module Franklin
7
- def run(config_path, search_terms, out)
8
- config = Config.load_from_file(config_path)
8
+ def run(search_terms, opts)
9
+ config = Config.load_from_file(opts[:config_path])
9
10
  results = ThreadedSearch.new(config.libraries).perform(search_terms)
10
- ConsoleReport.new(search_terms, results).print_to_out(out)
11
+ filtered_results = TypeFilter.new(opts[:type] || config.default_type).perform(results)
12
+ ConsoleReport.new(search_terms, filtered_results).print_to_out(opts[:out])
11
13
  end
12
14
 
13
15
  module_function :run
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: franklin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ylan Segal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -137,6 +137,7 @@ files:
137
137
  - lib/franklin/search.rb
138
138
  - lib/franklin/templates/console_report.erb
139
139
  - lib/franklin/threaded_search.rb
140
+ - lib/franklin/type_filter.rb
140
141
  - lib/franklin/version.rb
141
142
  homepage: https://github.com/ylansegal/franklin
142
143
  licenses:
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  version: '0'
159
160
  requirements: []
160
161
  rubyforge_project:
161
- rubygems_version: 2.4.5.1
162
+ rubygems_version: 2.5.1
162
163
  signing_key:
163
164
  specification_version: 4
164
165
  summary: CLI utility for searching Overdrive-powered public libraries