Permalink
Browse files

hard wrapping clue text to 80 character width - closes #17

  • Loading branch information...
1 parent e3510ee commit 5be20cbf42415ac59f67fc61692081966ebd4c29 @ryanb committed Jan 3, 2010
Showing with 14 additions and 1 deletion.
  1. +2 −0 CHANGELOG.rdoc
  2. +4 −0 lib/ruby_warrior/core_additions.rb
  3. +1 −1 lib/ruby_warrior/game.rb
  4. +7 −0 spec/ruby_warrior/core_additions_spec.rb
View
@@ -1,3 +1,5 @@
+* Hard wrapping clue text to 80 characters
+
* Mention direction when ability is performed
@@ -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
View
@@ -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
@@ -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

0 comments on commit 5be20cb

Please sign in to comment.