class Alexandria::GoodreadsCSVImport

Public Class Methods

new(header) click to toggle source
Calls superclass method Alexandria::CSVImport::new
# File lib/alexandria/import_library_csv.rb, line 48
def initialize(header)
  super(header)
  @title = index_of("Title")
  @author = index_of("Author")
  @additional_authors = index_of("Additional Authors")
  @isbn = index_of("ISBN")
  @publisher = index_of("Publisher")
  @publishing_year = index_of("Year Published")
  @edition = index_of("Binding")

  # optional extras
  @notes = index_of("Private Notes")
  @rating = index_of("My Rating")
  @read_count = index_of("Read Count")
  @date_read = index_of("Date Read")
  @bookshelves = index_of("Bookshelves") # save names as tags
  @mainshelf = index_of("Exclusive Shelf")
end

Public Instance Methods

row_to_book(row) click to toggle source
# File lib/alexandria/import_library_csv.rb, line 67
def row_to_book(row)
  title = normalize(row[@title])
  authors = []
  authors << normalize(row[@author])
  additional = row[@additional_authors]
  additional.split(",").each do |add|
    authors << normalize(add)
  end
  isbn = Library.canonicalise_ean(row[@isbn])
  publisher = normalize(row[@publisher])
  year = row[@publishing_year].to_i
  edition = normalize(row[@edition])
  book = Alexandria::Book.new(title,
                              authors,
                              isbn,
                              publisher,
                              year,
                              edition)
  book.notes = normalize(row[@notes]) if row[@notes]
  book.rating = row[@rating].to_i if row[@rating]
  if row[@read_count]
    count = row[@read_count].to_i
    book.redd = true if count > 0
  end
  if row[@date_read]
    date = Date.strptime(str, "%d/%m/%y") # e.g. "14/01/10" => 2010-01-14
    book.redd_when = date
    book.redd = true
  end
  if row[@mainshelf]
    case row[@mainshelf]
    when "read"
      book.redd = true
    when "to-read"
      book.redd = false
      book.tags = ["to read"]
    when "currently-reading"
      book.redd = false
      book.tags = ["currently reading"]
    end
  end
  if row[@bookshelves]
    shelves = normalize(row[@bookshelves]).split
    shelves.each do |shelf|
      tag = shelf.tr("-", " ")
      book.tags << tag unless book.tags.include? tag
    end
  end
  log.debug { "Goodreads loading #{book.title}" }
  book
end