class Rowling::BookList

Attributes

book_list_api_url[RW]
books[RW]
date[RW]
name[RW]

Public Class Methods

new(response) click to toggle source
# File lib/rowling/book_list.rb, line 3
def initialize(response)
  self.books = parse_entries(response["BookListEntries"])
  self.date = parse_date(response["BookListDate"])
  self.name = response["Name"]
  self.book_list_api_url = response["BookListDate"]["BookListAPIUrl"]
end

Public Instance Methods

parse_date(date_response) click to toggle source
# File lib/rowling/book_list.rb, line 12
def parse_date(date_response)
  date_vals = [date_response["Year"], date_response["Month"], date_response["Date"]]
  date_vals = date_vals.compact.map(&:to_i)
  Date.new(*date_vals)
end
parse_entries(entries_response) click to toggle source
# File lib/rowling/book_list.rb, line 18
def parse_entries(entries_response)
  books = entries_response.map.with_index do |entry, i|
    [i, book = Rowling::Book.new(entry)]
  end
  books.to_h
end