Class: DidYouMean::Formatter

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

Instance Method Summary collapse

Constructor Details

#initialize(suggestions = []) ⇒ Formatter

Returns a new instance of Formatter.



3
4
5
# File 'lib/did_you_mean/formatter.rb', line 3

def initialize(suggestions = [])
  @suggestions = suggestions
end

Instance Method Details

#format(name) ⇒ Object



16
17
18
# File 'lib/did_you_mean/formatter.rb', line 16

def format(name)
  name
end

#to_sObject



7
8
9
10
11
12
13
14
# File 'lib/did_you_mean/formatter.rb', line 7

def to_s
  return "" if @suggestions.empty?

  output = "\n\n"
  output << "    Did you mean? #{format(@suggestions.first)}\n"
  output << @suggestions.drop(1).map{|word| "#{' ' * 18}#{format(word)}\n" }.join
  output << " " # for rspec
end