Created
October 8, 2014 02:34
-
-
Save NuckChorris/bdbab4828b59707e2cc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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