Sha256: c9d81a4b3764055f006b4b62ebd13a2644998f5ddc0a2a698ea84456ccde5526
Contents?: true
Size: 1015 Bytes
Versions: 16
Compression:
Stored size: 1015 Bytes
Contents
require 'singleton' module BibTeX class Filter include Singleton class << self # Hook called by Ruby if Filter is subclassed def inherited(base) base.class_eval { include Singleton } subclasses << base end # Returns a list of all current Filters def subclasses @subclasses ||= [] end end def apply(value) value end alias convert apply alias << apply end module Filters LOAD_PATH = [File.expand_path('..', __FILE__), 'filters'].join('/').freeze Dir.glob("#{LOAD_PATH}/*.rb").each do |filter| require filter end def self.resolve(filter) case when filter.respond_to?(:apply) filter when filter.respond_to?(:to_s) klass = Filter.subclasses.detect do |c| c.name == filter.to_s || c.name.split(/::/)[-1] =~ /^#{filter}$/i end klass && klass.instance else nil end end end end
Version data entries
16 entries across 16 versions & 1 rubygems