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.



12
13
14
# File 'lib/hyrum/formats/formatter.rb', line 12

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#format(messages, validation_result = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/hyrum/formats/formatter.rb', line 16

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