Class: Alexandria::GoodreadsCSVImport

Inherits:
CSVImport
  • Object
show all
Defined in:
lib/alexandria/import_library_csv.rb

Instance Method Summary collapse

Methods inherited from CSVImport

#index_of, #normalize

Constructor Details

#initialize(header) ⇒ GoodreadsCSVImport

Returns a new instance of GoodreadsCSVImport.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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

Instance Method Details

#row_to_book(row) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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