Class: Book

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

Overview

Book: contains info like title and creator also contains an array of chapters (Chapter class)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, creator, pub_date = Date.today, isbn = nil) ⇒ Book

Returns a new instance of Book.



7
8
9
10
11
12
# File 'lib/book.rb', line 7

def initialize(title, creator, pub_date = Date.today, isbn = nil)
  self.title = title
  self.creator = creator
  self.pub_date = pub_date
  self.isbn = isbn
end

Instance Attribute Details

#chaptersObject

Returns the value of attribute chapters.



4
5
6
# File 'lib/book.rb', line 4

def chapters
  @chapters
end

#creatorObject

Returns the value of attribute creator.



4
5
6
# File 'lib/book.rb', line 4

def creator
  @creator
end

#isbnObject

Returns the value of attribute isbn.



4
5
6
# File 'lib/book.rb', line 4

def isbn
  @isbn
end

#pub_dateObject

Returns the value of attribute pub_date.



4
5
6
# File 'lib/book.rb', line 4

def pub_date
  @pub_date
end

#pub_yearObject

Returns the value of attribute pub_year.



4
5
6
# File 'lib/book.rb', line 4

def pub_year
  @pub_year
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/book.rb', line 4

def title
  @title
end

Instance Method Details

#book_idObject



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

def book_id
  @book_id ||= (isbn || "urn:uuid:#{UUID.new.generate}")
end

#cc_urlObject



22
23
24
25
26
27
28
# File 'lib/book.rb', line 22

def cc_url
  # attribution only, free to distribute, modify, or use commercially:
  # "http://creativecommons.org/licenses/by/3.0/"

  # free to share with attribution, non-commercial, no derivatives
  "http://creativecommons.org/licenses/by-nc-nd/3.0/"
end