Class: NYTBestsellers::Book

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Book

Returns a new instance of Book.



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

def initialize(hash = {})
  hash.each do |key, value|
    self.send("#{key}=", value)
  end
  @genre = NYTBestsellers::Genre.find_by_name(hash[:genre])
  if !wol.empty? || !summary.empty?
    @genre.books << self 
    @@all << self
  end
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#genreObject

Returns the value of attribute genre.



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

def genre
  @genre
end

#publisherObject

Returns the value of attribute publisher.



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

def publisher
  @publisher
end

#summaryObject

Returns the value of attribute summary.



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

def summary
  @summary
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#wolObject

Returns the value of attribute wol.



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

def wol
  @wol
end

Class Method Details

.allObject



17
18
19
# File 'lib/nytimes/book.rb', line 17

def self.all
  @@all
end

.find_by_title(name) ⇒ Object



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

def self.find_by_title(name)
  self.all.find do |book| 
    if name == book.title
      book
    end
  end
end