Class: GoodreadsBooks::Book
- Inherits:
-
Object
- Object
- GoodreadsBooks::Book
- Defined in:
- lib/goodreads_books/book.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#awards_year ⇒ Object
Returns the value of attribute awards_year.
-
#category ⇒ Object
Returns the value of attribute category.
-
#category_url ⇒ Object
Returns the value of attribute category_url.
-
#description ⇒ Object
Returns the value of attribute description.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#vote ⇒ Object
Returns the value of attribute vote.
Class Method Summary collapse
-
.all ⇒ Object
– self.new_from_web_page –.
-
.find_all_by_year(awards_year) ⇒ Object
– save –.
-
.new_from_web_page(book_hash) ⇒ Object
– initialize –.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Book
constructor
A new instance of Book.
-
#save ⇒ Object
– self.all –.
Constructor Details
#initialize(attributes) ⇒ Book
Returns a new instance of Book.
6 7 8 9 10 |
# File 'lib/goodreads_books/book.rb', line 6 def initialize(attributes) attributes.each do |attr_name, attr_value| self.send("#{attr_name}=", attr_value) end end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def @author end |
#awards_year ⇒ Object
Returns the value of attribute awards_year.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def awards_year @awards_year end |
#category ⇒ Object
Returns the value of attribute category.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def category @category end |
#category_url ⇒ Object
Returns the value of attribute category_url.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def category_url @category_url end |
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def description @description end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def url @url end |
#vote ⇒ Object
Returns the value of attribute vote.
2 3 4 |
# File 'lib/goodreads_books/book.rb', line 2 def vote @vote end |
Class Method Details
.all ⇒ Object
– self.new_from_web_page –
17 18 19 |
# File 'lib/goodreads_books/book.rb', line 17 def self.all @@all end |
.find_all_by_year(awards_year) ⇒ Object
– save –
25 26 27 |
# File 'lib/goodreads_books/book.rb', line 25 def self.find_all_by_year(awards_year) self.all.select { |book| book.awards_year == awards_year } end |
.new_from_web_page(book_hash) ⇒ Object
– initialize –
12 13 14 15 |
# File 'lib/goodreads_books/book.rb', line 12 def self.new_from_web_page(book_hash) book = new(book_hash) book.save end |
Instance Method Details
#save ⇒ Object
– self.all –
21 22 23 |
# File 'lib/goodreads_books/book.rb', line 21 def save self.class.all << self end |