Sha256: 8204aa7316b0b73c9114113280a6ffdeef78890341be7dbb8d7af4c20aae7844

Contents?: true

Size: 752 Bytes

Versions: 3

Compression:

Stored size: 752 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
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
citeproc-ruby-1.0.2 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.0.1 lib/citeproc/ruby/renderer/history.rb
citeproc-ruby-1.0.0 lib/citeproc/ruby/renderer/history.rb