Skip to content
Browse files

merge with master

  • Loading branch information...
2 parents ee1b81a + ec5f398 commit 6e70c451e1f9d4ae0b664b429dd4a193e3199ea1 @breckenedge committed Nov 27, 2011
Showing with 7 additions and 5 deletions.
  1. +5 −3 lib/squarecoder/transcoder.rb
  2. +2 −2 spec/performance_spec.rb
View
8 lib/squarecoder/transcoder.rb
@@ -11,8 +11,10 @@ class Transcoder
include Singleton
# Encode a String in square code
- def self.encode a_string, ignore_whitespace = false
- raise Squarecoder::InputTooLong if a_string.length > MAX_LEN
+ def self.encode a_string, ignore_whitespace = false, ignore_max_length = false
+ if !ignore_max_length && a_string.length > MAX_LEN
+ raise Squarecoder::InputTooLong
+ end
if !ignore_whitespace && a_string.include?(' ')
raise Squarecoder::NoWhitespace
end
@@ -26,7 +28,7 @@ def self.encode a_string, ignore_whitespace = false
# Decode a String from square code
def self.decode a_string
- encode( a_string, true ).gsub(/ +/, '')
+ encode( a_string, true, true ).gsub(/ +/, '')
end
end
View
4 spec/performance_spec.rb
@@ -3,9 +3,9 @@
describe Squarecoder do
it 'should run both string methods' do
- a = "a_string_that_is_somewhat_long"
+ a = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghija"
puts Benchmark.measure {
- 100000.times do
+ 25000.times do
a.square_encode.square_decode.should == a
end
}

0 comments on commit 6e70c45

Please sign in to comment.
Something went wrong with that request. Please try again.