Class: Hyrum::Formats::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrum/formats/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Formatter

Returns a new instance of Formatter.



10
11
12
# File 'lib/hyrum/formats/formatter.rb', line 10

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/hyrum/formats/formatter.rb', line 8

def options
  @options
end

Instance Method Details

#format(messages) ⇒ Object



14
15
16
17
18
# File 'lib/hyrum/formats/formatter.rb', line 14

def format(messages)
  template_file = File.join(__dir__, 'templates', "#{options[:format]}.erb")
  template = ERB.new(File.read(template_file), trim_mode: '-')
  template.result_with_hash(messages: messages)
end