Class: BookwormBuddy::Book

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

Constant Summary collapse

ALL =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bestseller_hash) ⇒ Book

Returns a new instance of Book.



5
6
7
8
# File 'lib/bookworm_buddy/book.rb', line 5

def initialize(bestseller_hash)
    bestseller_hash.each {|key, value| self.send("#{key}=", value)}
    ALL << self 
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#description_urlObject

Returns the value of attribute description_url.



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

def description_url
  @description_url
end

#priceObject

Returns the value of attribute price.



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

def price
  @price
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.create(book_array) ⇒ Object



10
11
12
# File 'lib/bookworm_buddy/book.rb', line 10

def self.create(book_array)
    book_array.each {|book| self.new(book)}
end

.emptyObject



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

def self.empty
    ALL.clear
end

.list_books_by_category(category_number) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/bookworm_buddy/book.rb', line 14

def self.list_books_by_category(category_number)
    puts BookwormBuddy::Category::ALL[category_number.to_i - 1].name.colorize(:magenta)
    if ALL == [] 
        puts "\n""So sorry, that category seems to be empty at the moment. Check back soon!".colorize(:red)
        BookwormBuddy::CLI.new.main_menu
    else
    ALL.each_with_index {|book, index| puts "#{index+1}. \"#{book.title}\" - by: #{book.author} - #{book.price}"}
    end
end

.list_description(description) ⇒ Object



28
29
30
# File 'lib/bookworm_buddy/book.rb', line 28

def self.list_description(description)
    puts "#{description}"
end

.list_title(book) ⇒ Object



24
25
26
# File 'lib/bookworm_buddy/book.rb', line 24

def self.list_title(book)
    puts "'#{book.title}'".colorize(:magenta)
end