Class: CiteProc::Processor
- Inherits:
-
Object
- Object
- CiteProc::Processor
show all
- Extended by:
- Forwardable
- Includes:
- Abbreviate, Converters
- Defined in:
- lib/citeproc/processor.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
Attributes included from Abbreviate
#namespace
Instance Method Summary
collapse
Methods included from Abbreviate
#abbreviate, #abbreviations, #abbreviations=
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Processor
Returns a new instance of Processor.
28
29
30
31
|
# File 'lib/citeproc/processor.rb', line 28
def initialize(options = {})
@options, @items, @data = Processor.defaults.merge(options), {}, []
yield self if block_given?
end
|
Class Attribute Details
.defaults ⇒ Object
Returns the value of attribute defaults.
19
20
21
|
# File 'lib/citeproc/processor.rb', line 19
def defaults
@defaults
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
22
23
24
|
# File 'lib/citeproc/processor.rb', line 22
def data
@data
end
|
#engine ⇒ Object
33
34
35
|
# File 'lib/citeproc/processor.rb', line 33
def engine
@engine ||= Engine.autodetect(options).new(self)
end
|
#items ⇒ Object
Returns the value of attribute items.
22
23
24
|
# File 'lib/citeproc/processor.rb', line 22
def items
@items
end
|
#options ⇒ Object
Returns the value of attribute options.
22
23
24
|
# File 'lib/citeproc/processor.rb', line 22
def options
@options
end
|
Instance Method Details
#<<(item) ⇒ Object
58
59
60
61
|
# File 'lib/citeproc/processor.rb', line 58
def <<(item)
register(item)
self
end
|
#[](id) ⇒ Object
37
38
39
|
# File 'lib/citeproc/processor.rb', line 37
def [](id)
items[id.to_s]
end
|
#[]=(id, item) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/citeproc/processor.rb', line 41
def []=(id, item)
item = Item(item)
item.id = id.to_s
register(items)
end
|
#append(*arguments) ⇒ Object
96
97
98
|
# File 'lib/citeproc/processor.rb', line 96
def append(*arguments)
engine.append(CitationData.new(arguments.flatten(1)))
end
|
#bibliography(attributes = nil, &block) ⇒ Bibliography
Generates a bibliography for all items matching the passed-in selector conditions or block.
108
109
110
|
# File 'lib/citeproc/processor.rb', line 108
def bibliography(attributes = nil, &block)
engine.bibliography(Selector.new(attributes, &block))
end
|
#inspect ⇒ Object
116
117
118
|
# File 'lib/citeproc/processor.rb', line 116
def inspect
"#<CiteProc::Processor style=#{options[:style].inspect} locale=#{options[:locale].inspect} items=[#{items.length}]>"
end
|
#process(*arguments) ⇒ Object
92
93
94
|
# File 'lib/citeproc/processor.rb', line 92
def process(*arguments)
engine.process(CitationData.new(arguments.flatten(1)))
end
|
#register(item) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/citeproc/processor.rb', line 48
def register(item)
item = Item(item)
data << item
items[item.id.to_s] = item
rescue => e
raise "failed to register item #{item.inspect}: #{e.message}"
end
|
#render(mode, *arguments) ⇒ Object
112
113
114
|
# File 'lib/citeproc/processor.rb', line 112
def render(mode, *arguments)
engine.render(mode, CitationData.new(arguments.flatten(1)))
end
|
#update(*arguments) ⇒ Object
Also known as:
import
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/citeproc/processor.rb', line 63
def update(*arguments)
arguments.each do |argument|
case argument
when Item
register(argument)
when Array
argument.each { |item| register(item) }
when Hash
argument.each do |id, item|
id, item = id.to_s, Item(item)
if items.key?(id) && block_given?
items[id] = yield items[id], item
else
items[id] = item
end
end
else
raise "failed to register items #{argument.inspect}"
end
end
self
ensure
end
|