blob: 0103c4ec4f670818f9cf87e331bc6692b2dbe210 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
class Trocla::Formats
class Base
attr_reader :trocla
def initialize(trocla)
@trocla = trocla
end
end
class << self
def [](format)
formats[format.downcase]
end
def all
Dir[File.expand_path(File.join(File.dirname(__FILE__),'formats','*.rb'))].collect{|f| File.basename(f,'.rb').downcase }
end
def available?(format)
all.include?(format.downcase)
end
private
def formats
@@formats ||= Hash.new do |hash, format|
format = format.downcase
if File.exists?(path(format))
require "trocla/formats/#{format}"
hash[format] = (eval "Trocla::Formats::#{format.capitalize}")
else
raise "Format #{format} is not supported!"
end
end
end
def path(format)
File.expand_path(File.join(File.dirname(__FILE__),'formats',"#{format}.rb"))
end
end
end
|