Sha256: 3607fe48db24735180b3eee306a1846794249e84f8b5629cab03f09b3a138609
Contents?: true
Size: 977 Bytes
Versions: 4
Compression:
Stored size: 977 Bytes
Contents
require 'rubygems' require 'json' require 'rindle/collection' class Rindle class Collections < Hash class NoSuchFile < Exception; end def initialize(kindle_root) @collections_file = File.join(kindle_root, 'system', 'collections.json') end def self.load(kindle_root) Collections.new(kindle_root).load end def save hash = {} values.each do |coll| hash.merge! col.to_hash end File.open(@collections_file, 'w+') do |f| JSON.dump(hash, f) end end def load unless File.exists?(@collections_file) raise NoSuchFile, "Not found: #{@collections_file}" end hash = File.open(@collections_file, 'r') { |file| JSON.load(file) } hash.each_pair do |name, data| col = Collection.new name, :indices => data['items'], :last_access => data['lastAccess'] self[col.name] = col end self end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rindle-0.3.1 | lib/rindle/collections.rb |
rindle-0.3.0 | lib/rindle/collections.rb |
rindle-0.2.0 | lib/rindle/collections.rb |
rindle-0.1.1 | lib/rindle/collections.rb |