Class: DayBooks::Book

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

Constant Summary collapse

@@all =
[]
@@all_titles =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = nil, book_url = nil) ⇒ Book

Returns a new instance of Book.



8
9
10
11
# File 'lib/book.rb', line 8

def initialize(title = nil, book_url = nil)
  @title = title
  @book_url = book_url
end

Instance Attribute Details

#all_titlesObject

Returns the value of attribute all_titles.



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

def all_titles
  @all_titles
end

#book_urlObject

Returns the value of attribute book_url.



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

def book_url
  @book_url
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.allObject



13
14
15
# File 'lib/book.rb', line 13

def self.all
  @@all
end

.all_titlesObject



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

def self.all_titles
  @@all_titles
end

.create(title, book_url) ⇒ Object



35
36
37
38
39
# File 'lib/book.rb', line 35

def self.create(title, book_url)
  new_book = self.new(title, book_url)
  new_book.save
  new_book
end

.downcase_all_titlesObject



31
32
33
# File 'lib/book.rb', line 31

def self.downcase_all_titles
  @@all_titles.map {|title| title.downcase}
end

.empty_allObject



26
27
28
29
# File 'lib/book.rb', line 26

def self.empty_all
  @@all.clear
  @@all_titles.clear
end

Instance Method Details

#saveObject



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

def save
  @@all << self
  @@all_titles << @title
end