Sha256: 87f349efcad37005e37d1ee6c742679802945351ff862ad85f5df8bffaaaf27d

Contents?: true

Size: 1012 Bytes

Versions: 6

Compression:

Stored size: 1012 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
      }
      return ts_uniq.compact
    end

    def tuned?(book,type)
      b = tuned.by_id(book.book_id,type)
      return false unless b
      b.book_id == book.book_id and b.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

6 entries across 6 versions & 1 rubygems

Version Path
bookscan-0.5.7 lib/bookscan/cache.rb
bookscan-0.5.6 lib/bookscan/cache.rb
bookscan-0.5.4 lib/bookscan/cache.rb
bookscan-0.5.3 lib/bookscan/cache.rb
bookscan-0.5.2 lib/bookscan/cache.rb
bookscan-0.5.0 lib/bookscan/cache.rb