Class: DidYouMean::Formatter
- Inherits:
-
Object
- Object
- DidYouMean::Formatter
- Defined in:
- lib/did_you_mean/formatter.rb
Instance Method Summary collapse
- #format(name) ⇒ Object
-
#initialize(suggestions = []) ⇒ Formatter
constructor
A new instance of Formatter.
- #to_s ⇒ Object
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_s ⇒ Object
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 |