scrumbler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.3.0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.5.2"
7
+ gem "rcov", ">= 0"
8
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Eric Budd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ Scrumbler
2
+ =========
3
+
4
+ Scrumbler will scramble any bit of text you feed it such that the first and last letters stay the same, but everything else is scrambled.
5
+
6
+ What?
7
+ =====
8
+
9
+ In 2003, Cambridge researchers discovered that words scrambled such that
10
+
11
+ Aoccdrnig to rscheearch at Cmabrigde uinervtisy, it deosn't mttaer waht
12
+ oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist
13
+ and lsat ltteres are at the rghit pclae. The rset can be a tatol mses and
14
+ you can sitll raed it wouthit a porbelm. Tihs is bcuseae we do not raed
15
+ ervey lteter by it slef but the wrod as a wlohe.
16
+
17
+ In other news, the Cambridge research meme may be bunkum: http://www.snopes.com/language/apocryph/cambridge.asp
18
+
19
+ Installation
20
+ ------------
21
+
22
+ Scrumbler is a gem:
23
+
24
+ gem install scrumbler
25
+
26
+ Usage
27
+ -----
28
+
29
+ First, you should require the gem:
30
+
31
+ require 'rubygems'
32
+ require 'scrumbler'
33
+
34
+ Once this is done, Scrumbler can be activated in a number of ways. You can use a class method:
35
+
36
+ Scrumbler.scrumble('The quick brown fox jumps over the lazy dog.')
37
+
38
+ => "The qucik bworn fox jupms oevr the lazy dog."
39
+
40
+ ...or instatiate it:
41
+
42
+ Scrumbler.new('The quick brown fox jumps over the lazy dog.').scrumbled
43
+
44
+ => "The qucik bworn fox jmups over the lazy dog."
45
+
46
+ ... or, if you're feeling naughty, you can ask Scrumbler to monkeypatch String:
47
+
48
+ 'The quick brown fox jumps over the lazy dog.'.scrumble
49
+
50
+ NoMethodError: undefined method `scrumble' for "The quick brown fox jumps over the lazy dog.":String
51
+
52
+ Scrumble.release_the_monkeys!
53
+ 'The quick brown fox jumps over the lazy dog.'.scrumble
54
+
55
+ => "The qciuk bowrn fox jpmus over the lazy dog."
56
+
57
+ == Contributing to scrumbler
58
+
59
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
60
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
61
+ * Fork the project
62
+ * Start a feature/bugfix branch
63
+ * Commit and push until you are happy with your contribution
64
+ * Make sure to add tests for it.
65
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
66
+
67
+ == Copyright
68
+
69
+ Copyright (c) 2011 Eric Budd. See LICENSE.txt for further details.
70
+
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = "scrumbler"
15
+ gem.homepage = "http://github.com/Calamitous/scrumbler"
16
+ gem.license = "MIT"
17
+ gem.summary = "A readable word scrambler"
18
+ gem.description = "Scrambles the interiors of words, leaving the first and last letters intact!"
19
+ gem.email = "eric.b.budd@gmail.com"
20
+ gem.authors = ["Eric Budd"]
21
+ end
22
+ Jeweler::RubygemsDotOrgTasks.new
23
+
24
+ require 'rspec/core'
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new(:spec) do |spec|
27
+ spec.pattern = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "scrumbler #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,42 @@
1
+ class Scrumbler
2
+ attr_reader :original, :scrumbled
3
+
4
+ def self.scrumble(new_string)
5
+ self.new(new_string).enscrumble
6
+ end
7
+
8
+ def self.release_the_monkeys!
9
+ String.class_eval("def scrumble; Scrumbler.scrumble(self); end")
10
+ end
11
+
12
+ def initialize(new_string)
13
+ @original = new_string
14
+ @scrumbled = enscrumble
15
+ end
16
+
17
+ def enscrumble
18
+ @original.split(' ').map{ |x| word_scrumble(x) }.join(' ')
19
+ end
20
+
21
+ private
22
+
23
+ def word_scrumble(chunk)
24
+ word = chunk.scan(/[\w\d\'-]*/).join
25
+ other = chunk.scan(/[^\w\d\'-]*/).join
26
+
27
+ return chunk if word.length <= 3
28
+
29
+ start_length = word[1].chr == 'h' ? 2 : 1
30
+
31
+ first_bit = word[0..(start_length - 1)]
32
+ middle_bit = word[start_length..-2]
33
+ last_bit = word[-1].chr
34
+
35
+ scrumbled_word = [first_bit, scramble(middle_bit), last_bit].flatten.join
36
+ scrumbled_word + other
37
+ end
38
+
39
+ def scramble(text)
40
+ text.scan(/./).sort{|x,y| rand(3) - 1 }
41
+ end
42
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{scrumbler}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Budd"]
12
+ s.date = %q{2011-03-29}
13
+ s.description = %q{Scrambles the interiors of words, leaving the first and last letters intact!}
14
+ s.email = %q{eric.b.budd@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/scrumbler.rb",
28
+ "scrumbler.gemspec",
29
+ "spec/scrumbler_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/Calamitous/scrumbler}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{A readable word scrambler}
37
+ s.test_files = [
38
+ "spec/scrumbler_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,92 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'Scrumbler' do
4
+ describe '#new' do
5
+ it 'requires a string parameter' do
6
+ lambda { Scrumbler.new }.should raise_error
7
+ end
8
+
9
+ it 'exposes the provided string' do
10
+ test_string = 'A noisy noise annoys an oyster.'
11
+ Scrumbler.new(test_string).original.should == test_string
12
+ end
13
+
14
+ it 'automatically enscrumbles the string' do
15
+ test_string = 'A noisy noise annoys an oyster.'
16
+ Scrumbler.new(test_string).scrumbled.should_not == test_string
17
+ end
18
+ end
19
+
20
+ describe '#enscrumble' do
21
+ it 'returns a scrumbled string' do
22
+ test_string = 'A noisy noise annoys an oyster.'
23
+ Scrumbler.new(test_string).enscrumble.should match(/^A n...y n...e a....s an o....r\.$/)
24
+ end
25
+
26
+ it 'handles words with dashes' do
27
+ test_string = 'en-scrumble'
28
+ Scrumbler.new(test_string).enscrumble.should match(/e.........e/)
29
+ end
30
+
31
+ it "handles words with apostrophes" do
32
+ test_string = "don't won't shan't"
33
+ Scrumbler.new(test_string).enscrumble.should match(/d...t w...t s....t/)
34
+ end
35
+
36
+ it 'steps around punctuation' do
37
+ test_string = 'How, without interjections?'
38
+ Scrumbler.new(test_string).enscrumble.should match(/How, w.....t i..........s?/)
39
+ end
40
+ end
41
+
42
+ describe '.scrumble' do
43
+ it 'returns a scrumbled string' do
44
+ test_string = 'A noisy noise annoys an oyster.'
45
+ Scrumbler.scrumble(test_string).should match(/^A n...y n...e a....s an o....r\.$/)
46
+ end
47
+
48
+ it 'handles words with dashes' do
49
+ test_string = 'en-scrumble'
50
+ Scrumbler.scrumble(test_string).should match(/e.........e/)
51
+ end
52
+
53
+ it 'handles words with apostrophes' do
54
+ test_string = "don't won't shan't"
55
+ Scrumbler.scrumble(test_string).should match(/d...t w...t s....t/)
56
+ end
57
+
58
+ it 'steps around punctuation' do
59
+ test_string = 'How, without interjections?'
60
+ Scrumbler.scrumble(test_string).should match(/How, w.....t i..........s?/)
61
+ end
62
+ end
63
+
64
+ describe '.release_the_monkeys!' do
65
+ it 'monkeypatches the String class to add #scrumble' do
66
+ 'Hello'.should_not respond_to(:scrumble)
67
+ Scrumbler.release_the_monkeys!
68
+ 'Hello'.should respond_to(:scrumble)
69
+ end
70
+
71
+ context 'once the monkeys have been released' do
72
+ before { Scrumbler.release_the_monkeys! }
73
+
74
+ it 'returns a scrumbled string' do
75
+ 'A noisy noise annoys an oyster'.scrumble.should match(/^A n...y n...e a....s an o....r$/)
76
+ end
77
+
78
+ it 'handles words with dashes' do
79
+ 'en-scrumble'.scrumble.should match(/^e.........e$/)
80
+ end
81
+
82
+ it 'handles words with apostrophes' do
83
+ "don't won't shan't".scrumble.should match(/^d...t w...t s....t$/)
84
+ end
85
+
86
+ it 'steps around punctuation' do
87
+ 'How, without more stuff?'.scrumble.should match(/^How, w.....t m..e s...f\?/)
88
+ end
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'scrumbler'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrumbler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Eric Budd
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-29 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 2
30
+ - 3
31
+ - 0
32
+ version: 2.3.0
33
+ prerelease: false
34
+ name: rspec
35
+ requirement: *id001
36
+ type: :development
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ prerelease: false
50
+ name: bundler
51
+ requirement: *id002
52
+ type: :development
53
+ - !ruby/object:Gem::Dependency
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 2
64
+ version: 1.5.2
65
+ prerelease: false
66
+ name: jeweler
67
+ requirement: *id003
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ prerelease: false
80
+ name: rcov
81
+ requirement: *id004
82
+ type: :development
83
+ description: Scrambles the interiors of words, leaving the first and last letters intact!
84
+ email: eric.b.budd@gmail.com
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ files:
93
+ - .document
94
+ - .rspec
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - VERSION
100
+ - lib/scrumbler.rb
101
+ - scrumbler.gemspec
102
+ - spec/scrumbler_spec.rb
103
+ - spec/spec_helper.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/Calamitous/scrumbler
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.3.7
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: A readable word scrambler
138
+ test_files:
139
+ - spec/scrumbler_spec.rb
140
+ - spec/spec_helper.rb