Module: Had::Formatters
- Extended by:
- Formatters
- Included in:
- Formatters
- Defined in:
- lib/had/formatters.rb,
lib/had/formatters/base.rb,
lib/had/formatters/html.rb,
lib/had/formatters/json.rb
Defined Under Namespace
Classes: Base, HTML, JSON
Instance Method Summary
collapse
Instance Method Details
#process(records) ⇒ Object
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
|
# File 'lib/had/formatters.rb', line 5
def process(records)
formatters = Had.configuration.formatters
raise 'No formatters defined' if formatters.empty?
formatters.each do |fmt|
case fmt
when 'html'
HTML.new(records).process
when 'json'
JSON.new(records).process
else
begin
klass = Object.const_get(fmt)
unless klass.public_instance_methods.include?(:process)
raise "Formatter #{fmt} should respond to `process` method"
end
klass.new(records).process
rescue NameError => e
if e.message =~ /(uninitialized constant|wrong constant name) #{fmt}$/
raise "Formatter #{fmt} does not exists"
else
raise e
end
end
end
end
end
|