Class: Athenaeum::Loan
- Inherits:
-
Object
- Object
- Athenaeum::Loan
- 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
-
Ben Bleything <[email protected]>
Copyright
Copyright © 2007 LAIKA, Inc
Version
$Id: loan.rb 289 2007-08-01 23:17:06Z bbleything $
Instance Attribute Summary collapse
-
#borrower ⇒ Object
readonly
Returns the value of attribute borrower.
-
#due_date ⇒ Object
readonly
Returns the value of attribute due_date.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Class Method Summary collapse
-
.find_by_borrower_id(id) ⇒ Object
searches the Loan registry and returns all loans that belong to the specified borrower.
-
.find_by_item_uuid(uuid) ⇒ Object
searches the Loan registry and returns the loan for the item with the given uuid, if any.
-
.registry ⇒ Object
simple getter for the loan registry.
Instance Method Summary collapse
-
#initialize(borrower, loan) ⇒ Loan
constructor
take a borrower and a loan tag, and create an object to encapsulate them.
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
#borrower ⇒ Object (readonly)
Returns the value of attribute borrower.
24 25 26 |
# File 'lib/athenaeum/loan.rb', line 24 def borrower @borrower end |
#due_date ⇒ Object (readonly)
Returns the value of attribute due_date.
24 25 26 |
# File 'lib/athenaeum/loan.rb', line 24 def due_date @due_date end |
#item ⇒ Object (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 |
.registry ⇒ Object
simple getter for the loan registry
48 49 50 51 |
# File 'lib/athenaeum/loan.rb', line 48 def self::registry @@registry ||= [] return @@registry end |