Class: Athenaeum::Loan

Inherits:
Object
  • Object
show all
Defined in:
lib/athenaeum/loan.rb

Overview

Athenaeum::Loan

Synopsis

Encapsulates the relationship between a borrower and an item. Any instance of this class represented an item that has been loaned out to a particular person.

Authors

Copyright © 2007 LAIKA, Inc

Version

$Id: loan.rb 289 2007-08-01 23:17:06Z bbleything $

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(borrower, loan) ⇒ Loan

take a borrower and a loan tag, and create an object to encapsulate them. Searches the Item registry for the item.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/athenaeum/loan.rb', line 28

def initialize( borrower, loan )
  raise "Must provide an Athenaeum::Borrower object" unless
    borrower.is_a? Athenaeum::Borrower

  raise "Must provide an Hpricot::Elem object" unless
    loan.is_a? Hpricot::Elem
  
  @item     = Athenaeum::Item.find_by_uuid( loan[ :mediaID ] )
  @borrower = borrower
  @due_date = Date.strptime( loan[ :dueDate ], '%d-%m-%Y' )
  
  @@registry ||= []
  @@registry << self
end

Instance Attribute Details

#borrowerObject (readonly)

Returns the value of attribute borrower.



24
25
26
# File 'lib/athenaeum/loan.rb', line 24

def borrower
  @borrower
end

#due_dateObject (readonly)

Returns the value of attribute due_date.



24
25
26
# File 'lib/athenaeum/loan.rb', line 24

def due_date
  @due_date
end

#itemObject (readonly)

Returns the value of attribute item.



24
25
26
# File 'lib/athenaeum/loan.rb', line 24

def item
  @item
end

Class Method Details

.find_by_borrower_id(id) ⇒ Object

searches the Loan registry and returns all loans that belong to the specified borrower.



66
67
68
69
# File 'lib/athenaeum/loan.rb', line 66

def self::find_by_borrower_id( id )
  @@registry ||= []
  return @@registry.select {|loan| loan.borrower.id == id }
end

.find_by_item_uuid(uuid) ⇒ Object

searches the Loan registry and returns the loan for the item with the given uuid, if any.



59
60
61
62
# File 'lib/athenaeum/loan.rb', line 59

def self::find_by_item_uuid( uuid )
  @@registry ||= []
  return @@registry.detect {|loan| loan.item.uuid == uuid }
end

.registryObject

simple getter for the loan registry



48
49
50
51
# File 'lib/athenaeum/loan.rb', line 48

def self::registry
  @@registry ||= []
  return @@registry
end