Class: CiteProc::Ruby::Renderer::State

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/citeproc/ruby/renderer/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



33
34
35
36
# File 'lib/citeproc/ruby/renderer/state.rb', line 33

def initialize
  @history, @authors = History.new(self, 3), []
  reset
end

Instance Attribute Details

#authorsObject (readonly)

Returns the value of attribute authors.



31
32
33
# File 'lib/citeproc/ruby/renderer/state.rb', line 31

def authors
  @authors
end

#historyObject (readonly)

Returns the value of attribute history.



31
32
33
# File 'lib/citeproc/ruby/renderer/state.rb', line 31

def history
  @history
end

#itemObject (readonly)

Returns the value of attribute item.



31
32
33
# File 'lib/citeproc/ruby/renderer/state.rb', line 31

def item
  @item
end

#nodeObject (readonly)

Returns the value of attribute node.



31
32
33
# File 'lib/citeproc/ruby/renderer/state.rb', line 31

def node
  @node
end

#substituteObject (readonly)

Returns the value of attribute substitute.



31
32
33
# File 'lib/citeproc/ruby/renderer/state.rb', line 31

def substitute
  @substitute
end

Instance Method Details

#clear!(result = nil) ⇒ Object



50
51
52
53
54
55
# File 'lib/citeproc/ruby/renderer/state.rb', line 50

def clear!(result = nil)
  memories = conserve(result)
  reset
ensure
  notify_observers :clear!, memories.delete(:mode), memories
end

#clear_substitute!(backup = nil) ⇒ Object



72
73
74
# File 'lib/citeproc/ruby/renderer/state.rb', line 72

def clear_substitute!(backup = nil)
  @substitute = backup
end

#conserve(result = nil) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/citeproc/ruby/renderer/state.rb', line 91

def conserve(result = nil)
  {
    :mode => mode,
    :item => item,
    :authors => authors,
    :result => result
  }
end

#modeObject



64
65
66
# File 'lib/citeproc/ruby/renderer/state.rb', line 64

def mode
  node && node.nodename
end

#previous_authorsObject



76
77
78
79
80
81
# File 'lib/citeproc/ruby/renderer/state.rb', line 76

def previous_authors
  past = history.recall(mode)
  return unless past && !past.empty?

  past[:authors]
end

#rendered_names!Object



87
88
89
# File 'lib/citeproc/ruby/renderer/state.rb', line 87

def rendered_names!
  @names = true
end

#rendered_names?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/citeproc/ruby/renderer/state.rb', line 83

def rendered_names?
  @names
end

#resetObject



57
58
59
60
61
62
# File 'lib/citeproc/ruby/renderer/state.rb', line 57

def reset
  @item, @node, @substitute, @authors, @names = nil, nil, nil, [], nil
  self
ensure
  changed
end

#store!(item, node) ⇒ Object



38
39
40
41
42
# File 'lib/citeproc/ruby/renderer/state.rb', line 38

def store!(item, node)
  @item, @node = item, node
ensure
  changed
end

#store_authors!(authors) ⇒ Object



44
45
46
47
48
# File 'lib/citeproc/ruby/renderer/state.rb', line 44

def store_authors!(authors)
  @authors << authors
ensure
  changed
end

#substitute!(names) ⇒ Object



68
69
70
# File 'lib/citeproc/ruby/renderer/state.rb', line 68

def substitute!(names)
  @substitute = names
end