Class: Alma::RenewalResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/alma/renewal_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response, loan = nil) ⇒ RenewalResponse

Returns a new instance of RenewalResponse.



4
5
6
7
8
9
# File 'lib/alma/renewal_response.rb', line 4

def initialize(response, loan=nil)
  @loan     = loan
  @success  = response.fetch('item_loan', nil)
  @error    = response.fetch('web_service_result', nil)
  @renewed  = @error.nil?
end

Instance Method Details

#error_messageObject



19
20
21
# File 'lib/alma/renewal_response.rb', line 19

def error_message
  @error['errorList']['error']['errorMessage']
end

#item_titleObject



23
24
25
26
27
28
29
# File 'lib/alma/renewal_response.rb', line 23

def item_title
  if @loan
    @loan.title
  else
    "This Item"
  end
end

#messageObject



31
32
33
34
35
36
37
# File 'lib/alma/renewal_response.rb', line 31

def message
  if @success
    "#{item_title} is now due #{new_due_date}"
  else
    "#{item_title} could not be renewed."
  end
end

#new_due_dateObject



15
16
17
# File 'lib/alma/renewal_response.rb', line 15

def new_due_date
  Time.parse(@success['due_date']).strftime('%m-%e-%y %H:%M')
end

#renewed?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/alma/renewal_response.rb', line 11

def renewed?
  @renewed
end