Class: BestReads::Book

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorObject

Returns the value of attribute author.



2
3
4
# File 'lib/best_reads/book.rb', line 2

def author
  @author
end

#displayObject (readonly)

Returns the value of attribute display.



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

def display
  @display
end

#ratingObject

Returns the value of attribute rating.



2
3
4
# File 'lib/best_reads/book.rb', line 2

def rating
  @rating
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/best_reads/book.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/best_reads/book.rb', line 2

def url
  @url
end

Class Method Details

.allObject



24
25
26
# File 'lib/best_reads/book.rb', line 24

def self.all
  @@all
end

.create_and_display_from_collection(book_hash) ⇒ Object



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

def self.create_and_display_from_collection(book_hash)
  book_hash.each_with_index do |book, index|
    new_book = self.new()
    book.each {|key, value| new_book.send(("#{key}="),value.strip)}
    new_book.save
    new_book.display_by_index(index)
  end
end

Instance Method Details

#display_by_index(index) ⇒ Object



15
16
17
18
# File 'lib/best_reads/book.rb', line 15

def display_by_index(index)
  puts "#{index+1}. #{self.title} by #{self.author}"
  puts "rating: #{self.rating}"
end

#saveObject



20
21
22
# File 'lib/best_reads/book.rb', line 20

def save
  self.class.all<<self
end