Class: GoodreadsBooks::Book

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#awards_yearObject

Returns the value of attribute awards_year.



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

def awards_year
  @awards_year
end

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#category_urlObject

Returns the value of attribute category_url.



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

def category_url
  @category_url
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#voteObject

Returns the value of attribute vote.



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

def vote
  @vote
end

Class Method Details

.allObject

– 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

#saveObject

– self.all –



21
22
23
# File 'lib/goodreads_books/book.rb', line 21

def save
  self.class.all << self
end