fahrenheit-aleph_ubpb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ca905976f08efc8f5a0949567bd6025580ad5f7
4
+ data.tar.gz: 1cb823fc050a71b68f53a37e33803c8ec1205b63
5
+ SHA512:
6
+ metadata.gz: ee8791ad96aa6b88c72792575f2c7f151dfd6de5debd83d9b29802213d147654d278dd24f7f46d3d037fe6e8955993c165a2358041603594e82ac4f2d6a98d5c
7
+ data.tar.gz: 9d208f89cc6539d970c8d01c4298f3d1b18d95888fd3cf525a375d4cb870bc3133783e8c554ade1d8d912555eb41e72cf4558af0a19a6bcbb6cd1346634c2157
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fahrenheit-aleph_ubpb.gemspec
4
+ gemspec
5
+
6
+ gem "pry", "~> 0.9.12.6"
7
+ gem "pry-nav", "~> 0.2.3"
8
+ gem "pry-stack_explorer", "~> 0.4.9.1"
9
+ gem "pry-syntax-hacks", "~> 0.0.6"
10
+
11
+ gem "fahrenheit", path: "~/github/ubpb/fahrenheit"
12
+ gem "fahrenheit-aleph", path: "~/github/ubpb/fahrenheit-aleph"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michael Sievers
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Fahrenheit::AlephUbpb
2
+
3
+ ## API
4
+
5
+ ### record_get_items(record_id, options = {})
6
+
7
+ The following is added/changed with respect to [**Fahrenheit::Aleph::Adapter#get_record_items**](https://github.com/ubpb/fahrenheit-aleph#record_get_itemsrecord_id-options--)
8
+
9
+ #### Hit fields
10
+ * ```availability```
11
+ * indicator, if an item is available for users
12
+ * may be one of the following
13
+ * ```"available"```
14
+ * ```"restricted_available"```
15
+ * ```"not_available"```
16
+ * ```loan_status```
17
+ * the following ubpb specific loan status are recognized
18
+ * ```"canceled"``` (storniert)
19
+ * ```"in_process``` (in bearbeitung)
20
+ * ```"missing"``` (vermisst)
21
+ * ```"ordered"``` (bestellt)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fahrenheit/aleph_ubpb/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fahrenheit-aleph_ubpb"
8
+ spec.version = Fahrenheit::AlephUbpb::VERSION
9
+ spec.authors = ["Michael Sievers"]
10
+ spec.summary = %q{Ubpb specific aleph adapter (extensions)}
11
+ spec.homepage = "https://github.com/ubpb/fahrenheit-aleph_ubpb"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "fahrenheit-aleph"
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0", "< 4.0.0"
24
+ end
@@ -0,0 +1,11 @@
1
+ require "fahrenheit/aleph_ubpb/version"
2
+
3
+ module Fahrenheit
4
+ module AlephUbpb
5
+ require_relative "./aleph_ubpb/adapter"
6
+
7
+ def self.adjust_record_id(record_id)
8
+ record_id.rjust(9, "0").prepend("PAD_ALEPH") unless record_id.nil?
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require "fahrenheit/aleph/adapter"
2
+
3
+ class Fahrenheit::AlephUbpb::Adapter < Fahrenheit::Aleph::Adapter
4
+ require_relative "./adapter/record"
5
+ require_relative "./adapter/user"
6
+
7
+ include Record
8
+ include User
9
+ end
@@ -0,0 +1,40 @@
1
+ module Fahrenheit::AlephUbpb::Adapter::Record
2
+ require_relative "./record/get_items"
3
+
4
+ include GetItems
5
+ end
6
+
7
+ =begin
8
+ module Fahrenheit::AlephUbpb::Adapter::Items
9
+ require_relative "./items/status_codes"
10
+
11
+ def get_records_items(record_ids, document_base = @default_document_base)
12
+ result = super(Fahrenheit::AlephUbpb::Adapter::Items.normalize_record_ids(record_ids), document_base)
13
+
14
+ if result.is_a?(Hash)
15
+ result.each do |record_id, items|
16
+ if items.is_a?(Array)
17
+ items.map! do |item|
18
+ item.merge({
19
+ "loanable" => StatusCodes[item["status_code"]][:loanable],
20
+ "only_short_loanable" => StatusCodes[item["status_code"]][:only_short_loanable],
21
+ "present" => !item["loanable"] || item["on_shelf"]
22
+ })
23
+ end
24
+ end
25
+ end
26
+ else
27
+ result
28
+ end
29
+ end
30
+
31
+ #
32
+ private
33
+ #
34
+ def self.normalize_record_ids(record_ids)
35
+ record_ids.map do |record_id|
36
+ record_id.sub(/^PAD_ALEPH/, "")
37
+ end
38
+ end
39
+ end
40
+ =end
@@ -0,0 +1,12 @@
1
+ module Fahrenheit::AlephUbpb::Adapter::Record::GetItems
2
+ require_relative "./get_items/restful_api_result_transformation"
3
+
4
+ def record_get_items(record_id, options = {})
5
+ super_result = super(
6
+ record_id.gsub("PAD_ALEPH", "PAD01"),
7
+ options.merge(output_format: :ox_document)
8
+ )
9
+
10
+ RestfulApiResultTransformation.new.apply source: super_result, target: super_result
11
+ end
12
+ end
@@ -0,0 +1,97 @@
1
+ require "transformator"
2
+
3
+ class Fahrenheit::AlephUbpb::Adapter::Record::GetItems::RestfulApiResultTransformation
4
+ def apply(*args)
5
+ self.transformation.apply(*args)
6
+ end
7
+
8
+ def transformation
9
+ @transformation ||= Transformator::Transformation.new do
10
+ output_format :hash
11
+
12
+ process "hits/hits" do |hits_array_element, target|
13
+ # ubpb specific loan_status
14
+ unless find(hits_array_element, "loan_status")
15
+ find(hits_array_element, "_source/status") do |node|
16
+ loan_status =
17
+ case node.text.gsub(/requested/i, "") # Remove requested states
18
+ when /bestellt/i then "ordered" # Exemplar wurde bestellt
19
+ when /storniert/i then "canceled" # Exemplar wurde storniert
20
+ when /in bearbeitung/i then "in_process" # Exemplar ist in Bearbeitung
21
+ when /vermisst/i then "missing" # Exemplar wird vermisst
22
+ end
23
+
24
+ hits_array_element << element("loan_status", text: loan_status) if loan_status
25
+ end
26
+ end
27
+
28
+ unless find(hits_array_element, "availability")
29
+ find(hits_array_element, "_source/z30-item-status-code") do |node|
30
+ item_status_code = node.text
31
+ loan_status = find(hits_array_element, "loan_status") { |_node| _node.text }
32
+
33
+ availability =
34
+ # things such as "expected" can only be not_available, no matter what
35
+ if %w(expected).include?(loan_status)
36
+ "not_available"
37
+ # these are always restricted available, no matter what their loan status is
38
+ elsif [
39
+ "23", # Tischapparat
40
+ "32", # Nicht ausleihbar
41
+ "33", # Seminarapparat
42
+ "37", # Nicht ausleihbar
43
+ "38", # Nicht ausleihbar
44
+ "41", # Nicht ausleihbar
45
+ "42", # Nicht ausleihbar
46
+ "43", # Handapparat
47
+ "44", # Nicht ausleihbar
48
+ "48", # Nicht ausleihbar
49
+ "49", # Nicht ausleihbar
50
+ "50", # Nicht ausleihbar
51
+ "55", # Nicht ausleihbar
52
+ "58", # Nicht ausleihbar
53
+ "60", # Nicht ausleihbar
54
+ "68" # Magazin-Präsenzausleihe
55
+ ].include?(item_status_code)
56
+ "restricted_available"
57
+ # from here, the loan status comes into play
58
+ elsif %w(on_shelf).include?(loan_status)
59
+ if [
60
+ "20", # "Normalausleihe"
61
+ "21", # "Magazinausleihe
62
+ "24", # "Normalausleihe
63
+ "25", # "Normalausleihe
64
+ "26", # "Normalausleihe
65
+ "27", # "Magazinausleihe
66
+ "53", # "4-Wochen-Ausleihe
67
+ "63", # "6-Monats-Ausleihe
68
+ "73", # "FL Abholung, Keine Verl.
69
+ "74" # "FL Lesesaal, Keine Verl.
70
+ ].include?(item_status_code)
71
+ "available"
72
+ elsif [
73
+ "30", # Kurzausleihe
74
+ "31", # Magazin-Kurzausleihe
75
+ "34", # Kurzausleihe
76
+ "35", # Kurzausleihe
77
+ "36", # Kurzausleihe
78
+ "40", # Kurzausleihe
79
+ "47", # Magazin-Kurzausleihe
80
+ "53", # 4-Wochen-Ausleihe
81
+ "61" # Magazin-5-Tage-Ausleihe
82
+ ].include?(item_status_code)
83
+ "restricted_available"
84
+ else
85
+ raise "Unknown item status code!"
86
+ end
87
+ else
88
+ "not_available"
89
+ end
90
+
91
+ hits_array_element << element("availability", text: availability) if availability
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,42 @@
1
+ module Fahrenheit::AlephUbpb::Adapter::Items::StatusCodes
2
+ @@status_codes = {
3
+ 20 => { description: "Normalausleihe", loanable: true, only_short_loanable: false },
4
+ 21 => { description: "Magazinausleihe", loanable: true, only_short_loanable: false },
5
+ 23 => { description: "Tischapparat", loanable: false, only_short_loanable: false },
6
+ 24 => { description: "Normalausleihe", loanable: true, only_short_loanable: false },
7
+ 25 => { description: "Normalausleihe", loanable: true, only_short_loanable: false },
8
+ 26 => { description: "Normalausleihe", loanable: true, only_short_loanable: false },
9
+ 27 => { description: "Magazinausleihe", loanable: true, only_short_loanable: false },
10
+ 30 => { description: "Kurzausleihe", loanable: true, only_short_loanable: true },
11
+ 31 => { description: "Magazin-Kurzausleihe", loanable: true, only_short_loanable: true },
12
+ 32 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
13
+ 33 => { description: "Seminarapparat", loanable: false, only_short_loanable: false },
14
+ 34 => { description: "Kurzausleihe", loanable: true, only_short_loanable: true },
15
+ 35 => { description: "Kurzausleihe", loanable: true, only_short_loanable: true },
16
+ 36 => { description: "Kurzausleihe", loanable: true, only_short_loanable: true },
17
+ 37 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
18
+ 38 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
19
+ 40 => { description: "Kurzausleihe", loanable: true, only_short_loanable: true },
20
+ 41 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
21
+ 42 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
22
+ 43 => { description: "Handapparat", loanable: false, only_short_loanable: false },
23
+ 44 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
24
+ 47 => { description: "Magazin-Kurzausleihe", loanable: true, only_short_loanable: true },
25
+ 48 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
26
+ 49 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
27
+ 50 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
28
+ 53 => { description: "4-Wochen-Ausleihe", loanable: true, only_short_loanable: false },
29
+ 55 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
30
+ 58 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
31
+ 60 => { description: "Nicht ausleihbar", loanable: false, only_short_loanable: false },
32
+ 61 => { description: "Magazin-5-Tage-Ausleihe", loanable: true, only_short_loanable: true },
33
+ 63 => { description: "6-Monats-Ausleihe", loanable: true, only_short_loanable: false },
34
+ 68 => { description: "Magazin-Präsenzausleihe", loanable: false, only_short_loanable: false },
35
+ 73 => { description: "FL Abholung, Keine Verl.", loanable: true, only_short_loanable: false },
36
+ 74 => { description: "FL Lesesaal, Keine Verl.", loanable: true, only_short_loanable: false }
37
+ }
38
+
39
+ def self.[](status_code)
40
+ @@status_codes[status_code.to_i]
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ module Fahrenheit::AlephUbpb::Adapter::User
2
+ require_relative "./user/get_charges"
3
+ #require_relative "./user/get_former_loans"
4
+ #require_relative "./user/get_holds"
5
+ #require_relative "./user/get_loans"
6
+ #require_relative "./user/get_informations"
7
+
8
+ include GetCharges
9
+ #include GetFormerLoans
10
+ #include GetHolds
11
+ #include GetLoans
12
+ #include GetInformations
13
+ end
@@ -0,0 +1,7 @@
1
+ module Fahrenheit::AlephUbpb::Adapter::User::GetCharges
2
+ def user_get_charges(user_id, options = {})
3
+ super.map do |charge|
4
+ charge.merge "record_id" => Fahrenheit::AlephUbpb.adjust_record_id(charge["record_id"])
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Fahrenheit
2
+ module AlephUbpb
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ describe Fahrenheit::AlephUbpb::Adapter::Items do
2
+ describe ".normalize_record_ids" do
3
+ it "maps paderborn specific record ids to appropriate aleph system numbers" do
4
+ expect(described_class.normalize_record_ids(["PAD_ALEPH000857752"])).to eq(["000857752"])
5
+
6
+ # unknown case
7
+ expect(described_class.normalize_record_ids(["foo"])).to eq(["foo"])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ describe Fahrenheit::AlephUbpb do
2
+ end
@@ -0,0 +1,13 @@
1
+ module Helpers
2
+ module Httpi
3
+ def stub_httpi(method, filename)
4
+ (httpi_stub = Class.new).instance_eval <<-code
5
+ def self.#{method}(*args)
6
+ Struct.new(:body).new(read_asset("#{filename}"))
7
+ end
8
+ code
9
+
10
+ stub_const("HTTPI", httpi_stub, transfer_nested_constants: true)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require "fahrenheit/aleph_ubpb"
2
+ require "yaml"
3
+ require_relative "./helpers/httpi"
4
+ begin
5
+ require "pry"
6
+ rescue LoadError
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.include Helpers::Httpi
11
+ end
12
+
13
+ def read_asset(path_to_file)
14
+ File.read(File.expand_path(File.join(File.dirname(__FILE__), "assets", path_to_file)))
15
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fahrenheit-aleph_ubpb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Sievers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fahrenheit-aleph
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: 4.0.0
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 3.0.0
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: 4.0.0
75
+ description:
76
+ email:
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - ".rspec"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - fahrenheit-aleph_ubpb.gemspec
88
+ - lib/fahrenheit/aleph_ubpb.rb
89
+ - lib/fahrenheit/aleph_ubpb/adapter.rb
90
+ - lib/fahrenheit/aleph_ubpb/adapter/record.rb
91
+ - lib/fahrenheit/aleph_ubpb/adapter/record/get_items.rb
92
+ - lib/fahrenheit/aleph_ubpb/adapter/record/get_items/restful_api_result_transformation.rb
93
+ - lib/fahrenheit/aleph_ubpb/adapter/record/status_codes.rb
94
+ - lib/fahrenheit/aleph_ubpb/adapter/user.rb
95
+ - lib/fahrenheit/aleph_ubpb/adapter/user/get_charges.rb
96
+ - lib/fahrenheit/aleph_ubpb/version.rb
97
+ - spec/fahrenheit/aleph_ubpb/adapter/items_spec.rb
98
+ - spec/fahrenheit/aleph_ubpb_spec.rb
99
+ - spec/helpers/httpi.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/ubpb/fahrenheit-aleph_ubpb
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Ubpb specific aleph adapter (extensions)
125
+ test_files:
126
+ - spec/fahrenheit/aleph_ubpb/adapter/items_spec.rb
127
+ - spec/fahrenheit/aleph_ubpb_spec.rb
128
+ - spec/helpers/httpi.rb
129
+ - spec/spec_helper.rb
130
+ has_rdoc: