Skip to content

Instantly share code, notes, and snippets.

@NuckChorris
Created October 8, 2014 02:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NuckChorris/bdbab4828b59707e2cc3 to your computer and use it in GitHub Desktop.
Save NuckChorris/bdbab4828b59707e2cc3 to your computer and use it in GitHub Desktop.
require 'oj'
class HummingbirdListImport
include Enumerable
# Most ListImport systems shouldn't need a `list` parameter, since they separate manga and anime
# exports. We do, since our backups contain your whole library.
def initialize(str, list)
@list = Oj.load(str)[list.to_s]
# The class of the database we're matching against
@db = list.to_s.camelize.constantize
end
# Enumerate all the rows in the list
def each
@list.each do |row|
exact_keys = %w{episodes_watched rewatch_count rewatching notes status private rating}
hash = row.slice(exact_keys).symbolize_keys
hash[:last_watched] = Time.parse(row['last_watched'])
# We don't need to fuzzy-match, a simple id-match should suffice, since it's our own import
hash[:media] = HummingbirdListImport.find_by_id(row['anime']['id'])
yield hash
end
end
def self.find_by_id(id)
Anime.find(id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment