Class: Alexandria::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/alexandria/models/book.rb

Constant Summary collapse

DEFAULT_RATING =
0
MAX_RATING_STARS =
5
VALID_RATINGS =
(DEFAULT_RATING..MAX_RATING_STARS).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, authors, isbn, publisher, publishing_year, edition) ⇒ Book

Returns a new instance of Book.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/alexandria/models/book.rb', line 20

def initialize(title, authors, isbn, publisher, publishing_year,
               edition)

  @title = title
  @authors = authors
  @isbn = isbn
  @publisher = publisher
  @edition = edition # actually used for binding! (i.e. paperback or hardback)
  @notes = ""
  @saved_ident = ident
  @publishing_year = publishing_year
  @redd = false
  @own = true
  @want = true
  @tags = []
  @rating = DEFAULT_RATING
  # Need to implement bulk save function to update this
  @version = Alexandria::DATA_VERSION
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def authors
  @authors
end

#editionObject

Returns the value of attribute edition.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def edition
  @edition
end

#isbnObject

Returns the value of attribute isbn.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def isbn
  @isbn
end

#libraryObject

Returns the value of attribute library.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def library
  @library
end

#loanedObject

Returns the value of attribute loaned.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def loaned
  @loaned
end

#loaned_sinceObject

Returns the value of attribute loaned_since.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def loaned_since
  @loaned_since
end

#loaned_toObject

Returns the value of attribute loaned_to.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def loaned_to
  @loaned_to
end

#notesObject

Returns the value of attribute notes.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def notes
  @notes
end

#ownObject

Returns the value of attribute own.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def own
  @own
end

#publisherObject

Returns the value of attribute publisher.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def publisher
  @publisher
end

#publishing_yearObject

Returns the value of attribute publishing_year.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def publishing_year
  @publishing_year
end

#ratingObject

Returns the value of attribute rating.



14
15
16
# File 'lib/alexandria/models/book.rb', line 14

def rating
  @rating
end

#reddObject

Returns the value of attribute redd.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def redd
  @redd
end

#redd_whenObject

Returns the value of attribute redd_when.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def redd_when
  @redd_when
end

#saved_identObject

Returns the value of attribute saved_ident.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def saved_ident
  @saved_ident
end

#tagsObject

Returns the value of attribute tags.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def title
  @title
end

#versionObject

Returns the value of attribute version.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def version
  @version
end

#wantObject

Returns the value of attribute want.



9
10
11
# File 'lib/alexandria/models/book.rb', line 9

def want
  @want
end

Instance Method Details

#==(other) ⇒ Object



67
68
69
# File 'lib/alexandria/models/book.rb', line 67

def ==(other)
  other.is_a?(self.class) && (ident == other.ident)
end

#identObject



40
41
42
43
# File 'lib/alexandria/models/book.rb', line 40

def ident
  @isbn = nil if !@isbn.nil? && @isbn.empty?
  @isbn || @title.hash.to_s
end

#inspectObject



71
72
73
# File 'lib/alexandria/models/book.rb', line 71

def inspect
  "#<Alexandria::Book title: #{@title}>"
end

#loaned?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/alexandria/models/book.rb', line 51

def loaned?
  loaned || false
end

#own?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/alexandria/models/book.rb', line 63

def own?
  own || false
end

#redd?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/alexandria/models/book.rb', line 55

def redd?
  redd || false
end

#want?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/alexandria/models/book.rb', line 59

def want?
  want || false
end