Class: CiteProc::Engine Abstract
- Inherits:
-
Object
- Object
- CiteProc::Engine
- Extended by:
- Forwardable
- Includes:
- Converters
- Defined in:
- lib/citeproc/engine.rb
Overview
Class Attribute Summary collapse
- .default ⇒ Object
-
.subclasses ⇒ Object
readonly
Returns the value of attribute subclasses.
-
.type ⇒ Object
readonly
Returns the value of attribute type.
-
.version ⇒ Object
readonly
Returns the value of attribute version.
Instance Attribute Summary collapse
-
#processor ⇒ Object
Returns the value of attribute processor.
Class Method Summary collapse
-
.autodetect(options = {}) ⇒ Object
Returns the best available engine class or nil.
-
.available ⇒ Object
Returns a list of all available engine names.
-
.detect(name) ⇒ Object
Returns the engine class for the given name or nil.
-
.detect!(name, &block) ⇒ Object
Loads the engine with the given name and returns the engine class.
- .engine_name ⇒ Object
-
.load(name) ⇒ Object
Loads the engine by requiring the engine name.
- .priority ⇒ Object
Instance Method Summary collapse
- #append ⇒ Object
- #bibliography ⇒ Object
-
#initialize(processor = nil) {|_self| ... } ⇒ Engine
constructor
A new instance of Engine.
- #inspect ⇒ Object
- #process ⇒ Object
- #render ⇒ Object
- #update_items ⇒ Object
- #update_uncited_items ⇒ Object
Constructor Details
#initialize(processor = nil) {|_self| ... } ⇒ Engine
Returns a new instance of Engine.
78 79 80 81 |
# File 'lib/citeproc/engine.rb', line 78 def initialize(processor = nil) @processor = processor yield self if block_given? end |
Class Attribute Details
.default ⇒ Object
25 26 27 |
# File 'lib/citeproc/engine.rb', line 25 def default @default ||= autodetect or warn 'no citeproc engine found' end |
.subclasses ⇒ Object (readonly)
Returns the value of attribute subclasses.
13 14 15 |
# File 'lib/citeproc/engine.rb', line 13 def subclasses @subclasses end |
.type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/citeproc/engine.rb', line 13 def type @type end |
.version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/citeproc/engine.rb', line 13 def version @version end |
Instance Attribute Details
#processor ⇒ Object
Returns the value of attribute processor.
74 75 76 |
# File 'lib/citeproc/engine.rb', line 74 def processor @processor end |
Class Method Details
.autodetect(options = {}) ⇒ Object
Returns the best available engine class or nil.
44 45 46 47 48 49 50 51 |
# File 'lib/citeproc/engine.rb', line 44 def autodetect( = {}) load('citeproc-ruby') if subclasses.empty? subclasses.detect { |e| !.has_key?(:engine) || e.name == [:engine] and !.has_key?(:name) || e.name == [:name] } || subclasses.first end |
.available ⇒ Object
Returns a list of all available engine names.
61 62 63 |
# File 'lib/citeproc/engine.rb', line 61 def available subclasses.map(&:engine_name) end |
.detect(name) ⇒ Object
Returns the engine class for the given name or nil. If no suitable class is found and a block is given, executes the block and returns the result. The list of available engines will be passed to the block.
32 33 34 35 |
# File 'lib/citeproc/engine.rb', line 32 def detect(name) subclasses.detect { |e| e.name == name } || block_given? ? yield(subclasses) : nil end |
.detect!(name, &block) ⇒ Object
Loads the engine with the given name and returns the engine class.
38 39 40 41 |
# File 'lib/citeproc/engine.rb', line 38 def detect!(name, &block) load(name) block_given? ? detect(name, &block) : detect(name) end |
.engine_name ⇒ Object
65 66 67 |
# File 'lib/citeproc/engine.rb', line 65 def engine_name @name ||= name.gsub(/::/, '-').downcase # returns class name as fallback end |
.load(name) ⇒ Object
Loads the engine by requiring the engine name.
54 55 56 57 58 |
# File 'lib/citeproc/engine.rb', line 54 def load(name) require name.gsub(/-/,'/') rescue LoadError warn "failed to load #{name} engine: try to gem install #{name}" end |
.priority ⇒ Object
69 70 71 |
# File 'lib/citeproc/engine.rb', line 69 def priority @priority ||= 0 end |
Instance Method Details
#append ⇒ Object
93 94 95 |
# File 'lib/citeproc/engine.rb', line 93 def append raise NotImplementedByEngine end |
#bibliography ⇒ Object
97 98 99 |
# File 'lib/citeproc/engine.rb', line 97 def bibliography raise NotImplementedByEngine end |
#inspect ⇒ Object
113 114 115 |
# File 'lib/citeproc/engine.rb', line 113 def inspect "#<CiteProc::Engine #{name}-#{type}-#{version}>" end |
#process ⇒ Object
89 90 91 |
# File 'lib/citeproc/engine.rb', line 89 def process raise NotImplementedByEngine end |
#render ⇒ Object
101 102 103 |
# File 'lib/citeproc/engine.rb', line 101 def render raise NotImplementedByEngine end |
#update_items ⇒ Object
105 106 107 |
# File 'lib/citeproc/engine.rb', line 105 def update_items raise NotImplementedByEngine end |
#update_uncited_items ⇒ Object
109 110 111 |
# File 'lib/citeproc/engine.rb', line 109 def update_uncited_items raise NotImplementedByEngine end |