Skip to content

Commit

Permalink
hard wrapping clue text to 80 character width - closes ryanb#17
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jan 3, 2010
1 parent e3510ee commit 5be20cb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,5 @@
* Hard wrapping clue text to 80 characters

* Mention direction when ability is performed


Expand Down
4 changes: 4 additions & 0 deletions lib/ruby_warrior/core_additions.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/ruby_warrior/game.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions 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

0 comments on commit 5be20cb

Please sign in to comment.