Class: ScrapeGot::Books
- Inherits:
-
Object
- Object
- ScrapeGot::Books
- Defined in:
- lib/scrape_got/books.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#number_of_pages ⇒ Object
Returns the value of attribute number_of_pages.
-
#released ⇒ Object
Returns the value of attribute released.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Books
constructor
A new instance of Books.
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
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/scrape_got/books.rb', line 4 def name @name end |
#number_of_pages ⇒ Object
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 |
#released ⇒ Object
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_books ⇒ Object
7 8 9 |
# File 'lib/scrape_got/books.rb', line 7 def self.all_books @@all_books ||= self.load_books end |
.load_books ⇒ Object
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 |
.print_books ⇒ Object
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 |