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
# File 'lib/citeproc/ruby/renderer/state.rb', line 33

def initialize
  @history, @authors = History.new(self, 3), []
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



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

def clear!(result = nil)
  memories = conserve(result)
  @item, @node, @substitute, @authors, @names = nil, nil, nil, [], nil
ensure
  changed
  notify_observers :clear!, memories.delete(:mode), memories
end

#clear_substitute!(backup = nil) ⇒ Object



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

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

#conserve(result = nil) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/citeproc/ruby/renderer/state.rb', line 84

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

#modeObject



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

def mode
  node && node.nodename
end

#previous_authorsObject



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

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

  past[:authors]
end

#rendered_names!Object



80
81
82
# File 'lib/citeproc/ruby/renderer/state.rb', line 80

def rendered_names!
  @names = true
end

#rendered_names?Boolean

Returns:

  • (Boolean)


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

def rendered_names?
  @names
end

#store!(item, node) ⇒ Object



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

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

#store_authors!(authors) ⇒ Object



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

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

#substitute!(names) ⇒ Object



61
62
63
# File 'lib/citeproc/ruby/renderer/state.rb', line 61

def substitute!(names)
  @substitute = names
end