diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 9f60aba9..9c252238 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,5 @@ +* Hard wrapping clue text to 80 characters + * Mention direction when ability is performed diff --git a/lib/ruby_warrior/core_additions.rb b/lib/ruby_warrior/core_additions.rb index 227e6268..672bd6b3 100644 --- a/lib/ruby_warrior/core_additions.rb +++ b/lib/ruby_warrior/core_additions.rb @@ -22,4 +22,8 @@ def humanize def titleize underscore.humanize.gsub(/\b('?[a-z])/) { $1.capitalize } end + + def hard_wrap(width = 80) + gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip + end end diff --git a/lib/ruby_warrior/game.rb b/lib/ruby_warrior/game.rb index 275a12bb..f656531f 100644 --- a/lib/ruby_warrior/game.rb +++ b/lib/ruby_warrior/game.rb @@ -87,7 +87,7 @@ def play_current_level continue = false UI.puts "Sorry, you failed level #{current_level.number}. Change your script and try again." if !Config.skip_input? && current_level.clue && UI.ask("Would you like to read the additional clues for this level?") - UI.puts current_level.clue + UI.puts current_level.clue.hard_wrap end end continue diff --git a/spec/ruby_warrior/core_additions_spec.rb b/spec/ruby_warrior/core_additions_spec.rb new file mode 100644 index 00000000..beb18d89 --- /dev/null +++ b/spec/ruby_warrior/core_additions_spec.rb @@ -0,0 +1,7 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe String do + it "should wrap text at white space when over a specific character length" do + "foo bar blah".hard_wrap(10).should == "foo bar\nblah" + end +end