Class: NYTBestsellers::Genre

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Genre

Returns a new instance of Genre.



6
7
8
9
10
11
12
# File 'lib/nytimes/genre.rb', line 6

def initialize(hash = {})
  hash.each do |key, value|
    self.send("#{key}=", value)
  end  
  @@all << self
  @books = []
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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

def self.all 
  @@all
end

.find_by_name(genre_name) ⇒ Object



22
23
24
# File 'lib/nytimes/genre.rb', line 22

def self.find_by_name(genre_name)
  self.all.find {|x| x.name == genre_name}
end

.find_by_num(num_input) ⇒ Object



26
27
28
# File 'lib/nytimes/genre.rb', line 26

def self.find_by_num(num_input)
  self.all[num_input.to_i-1]
end

Instance Method Details

#booksObject



18
19
20
# File 'lib/nytimes/genre.rb', line 18

def books
  @books
end