HoustonLibrarySearch 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+ gem "nokogiri"
3
+ gem "curb"
@@ -0,0 +1,41 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{HoustonLibrarySearch}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nelson Morris"]
12
+ s.date = %q{2010-02-19}
13
+ s.description = %q{Search Houston area libraries for ISBNs}
14
+ s.email = %q{nmorris@nelsonmorris.net}
15
+ s.files = [
16
+ "Gemfile",
17
+ "HoustonLibrarySearch.gemspec",
18
+ "Rakefile",
19
+ "VERSION",
20
+ "lib/HoustonLibrarySearch.rb",
21
+ "lib/listing.rb",
22
+ "lib/plugins/HCPL.rb",
23
+ "lib/plugins/HPL.rb"
24
+ ]
25
+ s.homepage = %q{http://github.com/xeqi/HoustonLibrarySearch}
26
+ s.rdoc_options = ["--charset=UTF-8"]
27
+ s.require_paths = ["lib"]
28
+ s.rubygems_version = %q{1.3.5}
29
+ s.summary = %q{Search Houston area libraries for ISBNs}
30
+
31
+ if s.respond_to? :specification_version then
32
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
33
+ s.specification_version = 3
34
+
35
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
36
+ else
37
+ end
38
+ else
39
+ end
40
+ end
41
+
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = "HoustonLibrarySearch"
8
+ gemspec.summary = "Search Houston area libraries for ISBNs"
9
+ gemspec.description = "Search Houston area libraries for ISBNs"
10
+ gemspec.email = "nmorris@nelsonmorris.net"
11
+ gemspec.homepage = "http://github.com/xeqi/HoustonLibrarySearch"
12
+ gemspec.authors = ["Nelson Morris"]
13
+ gemspec.files = FileList["[A-Z]*", "{lib,test}/**/*"]
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,25 @@
1
+ begin
2
+ # Try to require the preresolved locked set of gems.
3
+ require File.expand_path('../.bundle/environment', __FILE__)
4
+ rescue LoadError
5
+ # Fall back on doing an unlocked resolve at runtime.
6
+ require "rubygems"
7
+ require "bundler"
8
+ Bundler.setup
9
+ end
10
+
11
+ require "curb"
12
+ require "nokogiri"
13
+ require File.join(File.expand_path(File.dirname(__FILE__)), "listing.rb")
14
+
15
+ Dir[File.join(File.expand_path(File.dirname(__FILE__)), "plugins/*.rb")].each {|file| require file }
16
+
17
+ class HoustonLibrarySearch
18
+ def self.search(isbn)
19
+ hash = {}
20
+ [HPL, HCPL].collect do |x|
21
+ hash.merge!({x.name => x.listings(isbn)})
22
+ end
23
+ hash
24
+ end
25
+ end
data/lib/listing.rb ADDED
@@ -0,0 +1,12 @@
1
+
2
+ class Listing
3
+
4
+ attr_reader :location, :call_number, :status, :due_date
5
+
6
+ def initialize(location, call_number, status, due_date)
7
+ @location = location
8
+ @call_number = call_number
9
+ @status = status
10
+ @due_date = due_date
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'curb'
2
+ require 'nokogiri'
3
+
4
+ class HCPL
5
+ def self.listings(isbn)
6
+ c = Curl::Easy.perform("http://catalog.hcpl.net/ipac20/ipac.jsp?index=ISBNEXH&term=#{isbn}")
7
+ xml = Nokogiri::XML.parse(c.body_str)
8
+ results = xml.css(".tableBackground .tableBackground .tableBackground .tableBackground .tableBackground .tableBackground").collect do |table|
9
+ trs = table.css("tr")
10
+ # mask multiple books as no results
11
+ # see isbn 0887307280
12
+ if(trs[0].css("td")[0].css("a").text =~ /Location/)
13
+ trs[1, trs.length-1].collect do |tr|
14
+ tds = tr.css("td")
15
+ Listing.new(tds[0].text, tds[2].text, tds[3].text, tds[4].text)
16
+ end
17
+ end
18
+ end
19
+ #handle masking
20
+ results = results.select{|x| x}
21
+ results.flatten
22
+ end
23
+
24
+ def self.name
25
+ "Harris County Public Library"
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'curb'
2
+ require 'nokogiri'
3
+
4
+ class HPL
5
+ def self.listings(isbn)
6
+ c = Curl::Easy.perform("http://catalog.houstonlibrary.org/search~S0/?searchtype=i&searcharg=#{isbn}")
7
+ xml = Nokogiri::XML.parse(c.body_str)
8
+ xml.css('.bibItemsEntry').collect do |x|
9
+ due = ''
10
+ row = x.css('td')
11
+ status = row[3].text.strip
12
+ if status =~ /DUE/
13
+ due = status[4, 8]
14
+ status = "Checked out"
15
+ end
16
+ Listing.new(row[0].text.strip, row[2].text.strip, status.capitalize, due)
17
+ end
18
+ end
19
+ def self.name
20
+ "Houston Public Library"
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: HoustonLibrarySearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nelson Morris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-19 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Search Houston area libraries for ISBNs
17
+ email: nmorris@nelsonmorris.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Gemfile
26
+ - HoustonLibrarySearch.gemspec
27
+ - Rakefile
28
+ - VERSION
29
+ - lib/HoustonLibrarySearch.rb
30
+ - lib/listing.rb
31
+ - lib/plugins/HCPL.rb
32
+ - lib/plugins/HPL.rb
33
+ has_rdoc: true
34
+ homepage: http://github.com/xeqi/HoustonLibrarySearch
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Search Houston area libraries for ISBNs
61
+ test_files: []
62
+