Class: LibyearRb::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/libyear_rb/formatters/formatter.rb

Direct Known Subclasses

JsonFormatter, PlaintextFormatter

Constant Summary collapse

NAMES =
%w[plaintext json].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io: $stdout, indirect: true) ⇒ Formatter

Returns a new instance of Formatter.



22
23
24
25
# File 'lib/libyear_rb/formatters/formatter.rb', line 22

def initialize(io: $stdout, indirect: true)
  @io = io
  @indirect = indirect
end

Class Method Details

.for(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/libyear_rb/formatters/formatter.rb', line 8

def for(name)
  case name
  when "plaintext"
    require "libyear_rb/formatters/plaintext_formatter"
    PlaintextFormatter
  when "json"
    require "libyear_rb/formatters/json_formatter"
    JsonFormatter
  else
    raise ArgumentError, "Unknown formatter: #{name.inspect}. Available formatters: #{NAMES.join(", ")}."
  end
end

Instance Method Details

#generate(results) ⇒ Object

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/libyear_rb/formatters/formatter.rb', line 27

def generate(results)
  raise NotImplementedError, "Subclasses must implement the generate method"
end