Class: ScrapeGot::Books

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Books

Returns a new instance of Books.



17
18
19
20
21
# File 'lib/scrape_got/books.rb', line 17

def initialize(attributes = {})
  @name = attributes["name"]
  @number_of_pages = attributes["numberOfPages"]
  @released = attributes["released"]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#number_of_pagesObject

Returns the value of attribute number_of_pages.



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

def number_of_pages
  @number_of_pages
end

#releasedObject

Returns the value of attribute released.



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

def released
  @released
end

Class Method Details

.all_booksObject



7
8
9
# File 'lib/scrape_got/books.rb', line 7

def self.all_books
  @@all_books ||= self.load_books
end

.load_booksObject



11
12
13
14
15
# File 'lib/scrape_got/books.rb', line 11

def self.load_books
  API.get_books.collect do |book_hash|
    Books.new(book_hash)
  end
end


23
24
25
26
27
# File 'lib/scrape_got/books.rb', line 23

def self.print_books
  Books.all_books.each.with_index(1) do |book, index|
    puts "Book #{index}: #{book.name}, released: #{book.released}"
  end
end