Sha256: e62abac8c4d0e5ae958e5d2b97b307e19e603044ca7957471ed627ed64e0bbf6

Contents?: true

Size: 984 Bytes

Versions: 4

Compression:

Stored size: 984 Bytes

Contents

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'pstore'

module Bookscan
  class Cache < PStore

    def groups
      gs = nil
      transaction do |ps|
        gs = ps["groups"]
      end
      raise "No groups in cache. Exceute 'bookscan update' first." unless gs
      gs
    end

    def tuned
      ts = nil
      transaction do |ps|
        ts = ps["tuned"]
      end
      ts_uniq = Books.new
      ts.each { |t|
        unless ts_uniq.find { |i| i.title == t.title }
          ts_uniq << t
        end
      }
      require 'pp'
      return ts_uniq.compact
    end

    def tuned?(book,type)
      tuned.has?(book.book_id) and tuned.by_id(book.book_id).tune_type == type
    end

    def books(group = nil)
      if group
        groups.each do |g|
          return g.books if g.hash == group.hash
        end
      else
        bs = Books.new
        groups.each do |g|
          g.books.each { |b| bs << b }
        end
        return bs
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bookscan-0.4.3 lib/bookscan/cache.rb
bookscan-0.4.1 lib/bookscan/cache.rb
bookscan-0.4.0 lib/bookscan/cache.rb
bookscan-0.3.0 lib/bookscan/cache.rb