-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.rb
94 lines (77 loc) · 1.7 KB
/
item.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
class Item
def initialize(data:)
@data = data
end
def self.for(barcode, options = {})
client = options[:alma_client] || AlmaRestClient.client(
Faraday.new do |f|
f.response :follow_redirects
end
)
alma_response = client.get("/items", query: {item_barcode: barcode, expand: "due_date"})
if alma_response.status == 200
Item.new(data: alma_response.body)
else
EmptyItem.new
end
end
def title
@data.dig("bib_data", "title")
end
def library
@data.dig("item_data", "library", "desc")
end
def location
@data.dig("item_data", "location", "desc")
end
def shelving_location
item_location = library || ""
if location != "NONE"
item_location << " #{location}"
end
item_location
end
def library_code
@data.dig("item_data", "library", "value")
end
def item_policy
@data.dig("item_data", "policy", "value")
end
def bookable?
library_code == "FVL" && ["08", "09"].exclude?(item_policy)
end
def call_number
@data.dig("holding_data", "call_number")
end
def barcode
@data.dig("item_data", "barcode")
end
def due_date
@data.dig("item_data", "due_date") || ""
end
def mms_id
@data.dig("bib_data", "mms_id")
end
def holding_id
@data.dig("holding_data", "holding_id")
end
def pid
@data.dig("item_data", "pid")
end
def catalog_url
"https://search.lib.umich.edu/catalog/record/#{mms_id}"
end
class EmptyItem < self
def initialize
@data = {}
end
# ['title', 'catalog_url', "library", "call_number", "pid",].each do |name|
# define_method(name) do
# ''
# end
# end
def bookable?
false
end
end
end