1 |
module CiteProc |
12✔ |
2 |
module Ruby |
12✔ |
3 |
class Renderer |
12✔ |
4 |
|
|
5 |
class History |
12✔ |
6 |
attr_reader :maxsize, :memory |
12✔ |
7 |
|
|
8 |
def initialize(state, maxsize = 10) |
364✔ |
9 |
@state, @maxsize, = state, maxsize |
959✔ |
10 |
@state.add_observer(self) |
959✔ |
11 |
|
|
12 |
@memory = Hash.new do |hash, key| |
959✔ |
13 |
hash[key] = [] |
86✔ |
14 |
end
|
|
15 |
end
|
|
16 |
|
|
17 |
def update(action, mode, memories = {}) |
64✔ |
18 |
history = memory[mode] |
165✔ |
19 |
history << memories |
165✔ |
20 |
|
|
21 |
ensure
|
|
22 |
history.shift if history.length > maxsize
|
155✔ |
23 |
end
|
|
24 |
|
|
25 |
def recall(mode) |
12✔ |
26 |
memory[mode][-1]
|
36✔ |
27 |
end
|
|
28 |
|
|
29 |
def citation |
12✔ |
30 |
memory['citation']
|
24✔ |
31 |
end
|
|
32 |
|
|
33 |
def bibliography |
12✔ |
34 |
memory['bibliography']
|
× |
35 |
end
|
|
36 |
end
|
|
37 |
|
|
38 |
end
|
|
39 |
end
|
|
40 |
end
|