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
|
# File 'lib/median/aleph/loan.rb', line 4
def get_loans(patron_id, options = {})
options = options.reverse_merge(history: false)
loans = []
url = "#{Median.config.aleph_rest_service_base_url}/patron/#{patron_id}/circulationActions/loans"
xml = options[:history] ?
get_url(url, view: 'brief', type: 'history', no_loans: 250) :
get_url(url, view: 'brief')
xml.xpath('//loan').each do |loan_xml|
loan = OpenStruct.new
loan.id = loan_xml.attribute('href').try(:content).try(:split, '/').try(:last)
loan.can_renew = (loan_xml.attribute('renew').try(:content).try(:upcase) == 'Y') ? true : false
loan.author = loan_xml.at_xpath('z13-author').try(:content)
loan.title = loan_xml.at_xpath('z13-title').try(:content)
loan.year = loan_xml.at_xpath('z13-year').try(:content)
return_date = loan_xml.at_xpath('z36h-returned-date').try(:content)
due_date = loan_xml.at_xpath('z36-due-date').try(:content)
loan.returned = return_date.present? ? Date.strptime(return_date, '%Y%m%d') : nil
loan.due = due_date.present? ? Date.strptime(due_date, '%Y%m%d') : nil
loans << loan
end
loans.sort{|x,y| x.due <=> y.due }
loans
end
|