Class: Rowling::BookList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ BookList

Returns a new instance of BookList.



3
4
5
6
7
8
# 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

Instance Attribute Details

#book_list_api_urlObject

Returns the value of attribute book_list_api_url.



10
11
12
# File 'lib/rowling/book_list.rb', line 10

def book_list_api_url
  @book_list_api_url
end

#booksObject

Returns the value of attribute books.



10
11
12
# File 'lib/rowling/book_list.rb', line 10

def books
  @books
end

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/rowling/book_list.rb', line 10

def date
  @date
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/rowling/book_list.rb', line 10

def name
  @name
end

Instance Method Details

#parse_date(date_response) ⇒ Object



12
13
14
15
16
# 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) ⇒ Object



18
19
20
21
22
23
# 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