Browse files

Add String#colorized?.

  • Loading branch information...
1 parent fd6370f commit c9add7589c1015e276086843390b4968d771b197 @benhoskings committed Jul 11, 2012
Showing with 13 additions and 0 deletions.
  1. +4 −0 lib/babushka/core_patches/string.rb
  2. +9 −0 spec/babushka/core_patches_spec.rb
View
4 lib/babushka/core_patches/string.rb
@@ -85,6 +85,10 @@ def to_version
Babushka::VersionStr.new self
end
+ def colorized?
+ self[/\e\[\d/]
+ end
+
# Return a new string with the contents of this string surrounded in escape
# sequences such that it will render as described in +description+.
# Some examples:
View
9 spec/babushka/core_patches_spec.rb
@@ -169,3 +169,12 @@ def version_of *args
"/dev/disk1s2 Apple_HFS /Volumes/TextMate 1.5.9".val_for(/^\/dev\/disk\d+s\d+\s+Apple_HFS\s+/).should == "/Volumes/TextMate 1.5.9"
end
end
+
+describe String, '#colorized?' do
+ it "should return false for regular strings" do
+ "babushka".should_not be_colorized
+ end
+ it "should return true for strings containing ANSI color sequences" do
+ "\e[0;32;29mbabushka\e[0m".should be_colorized
+ end
+end

0 comments on commit c9add75

Please sign in to comment.