-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook.rb
41 lines (34 loc) · 1.15 KB
/
book.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
require 'circulation_status'
class Book
attr_accessor :id, :title, :author, :isbn, :status
def initialize( hash = {:id => "0", :title => "", :author => "", :isbn => "", :status => CirculationStatus::STOCKED
} )
@id = hash[:id]
@title = hash[:title]
@author = hash[:author]
@isbn = hash[:isbn]
@status = hash.key?(:status) ? hash[:status] : CirculationStatus::STOCKED
end
def eql?(other)
return true if self.equal?(other)
return false if self.class != other.class
( self.id == other.id and
self.title == other.title and
self.author == other.author and
self.isbn == other.isbn and
self.status == other.status )
end
def hash
prime = 31
result = 1
result = prime * (result + (author.nil? ? 0 : author.hash))
result = prime * (result + (id.nil? ? 0 : id.hash))
result = prime * (result + (isbn.nil? ? 0 : isbn.hash))
result = prime * (result + (status.nil? ? 0 : status.hash))
result = prime * (result + (title.nil? ? 0 : title.hash))
result
end
def to_s
"Book[id=\"#{id}\", title=\"#{title}\", author=\"#{author}\", isbn=\"#{isbn}\", status=:#{status}]"
end
end