Sha256: 42e4a6b5c38dcdfda770fce3dda7366717045ab8bec72d2ce6785d0048cab4d7

Contents?: true

Size: 823 Bytes

Versions: 20

Compression:

Stored size: 823 Bytes

Contents

module CiteProc
  module Ruby
    class Renderer

      class History
        attr_reader :maxsize, :memory

        def initialize(state, maxsize = 10)
          @state, @maxsize, = state, maxsize
          @state.add_observer(self)

          @memory = Hash.new do |hash, key|
            hash[key] = []
          end
        end

        def update(action, mode, memories = {})
          history = memory[mode]
          history << memories

        ensure
          history.shift if history.length > maxsize
        end

        def recall(mode)
          memory[mode][-1]
        end

        def citation
          memory['citation']
        end

        def bibliography
          memory['bibliography']
        end

        def discard
          memory.clear
          self
        end
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
citeproc-ruby-2.1.0 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-2.0.0 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.14 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.13 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.12 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.11 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.10 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.8 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.7 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.6 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.5 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.4 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.3 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.2 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.1 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.1.0 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.0.6 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.0.5 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.0.4 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.0.3 lib/citeproc/ruby/renderer/history.rb