tweetspeak 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown ADDED
File without changes
data/bin/tweetspeak ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ require 'tweet_speak'
5
+
6
+ input = unless ARGV.empty?
7
+ ARGV.join(' ')
8
+ else
9
+ gets
10
+ end
11
+
12
+ puts TweetSpeak.twittify(input)
@@ -0,0 +1,21 @@
1
+ class TweetSpeak
2
+ SHORTHAND = {
3
+ 'are' => 'r',
4
+ 'you' => 'u',
5
+ 'your' => 'ur',
6
+ "you're" => 'ur',
7
+ 'to' => '2',
8
+ 'because' => 'b/c',
9
+ 'before' => 'b4',
10
+ 'for' => '4',
11
+ 'with' => 'w/',
12
+ 'without' => 'w/o'
13
+ }
14
+
15
+ def self.twittify(tweet)
16
+ regex = /(\W*)(#{SHORTHAND.keys.join('|')})(\W+|$)/i
17
+ tweet.gsub(regex) do |match|
18
+ $1 + SHORTHAND[$2] + $3
19
+ end.gsub(/\s+/, ' ')
20
+ end
21
+ end
data/test/contest.rb ADDED
@@ -0,0 +1,68 @@
1
+ require "test/unit"
2
+
3
+ # Test::Unit loads a default test if the suite is empty, whose purpose is to
4
+ # fail. Since having empty contexts is a common practice, we decided to
5
+ # overwrite TestSuite#empty? in order to allow them. Having a failure when no
6
+ # tests have been defined seems counter-intuitive.
7
+ class Test::Unit::TestSuite
8
+ def empty?
9
+ false
10
+ end
11
+ end
12
+
13
+ # Contest adds +teardown+, +test+ and +context+ as class methods, and the
14
+ # instance methods +setup+ and +teardown+ now iterate on the corresponding
15
+ # blocks. Note that all setup and teardown blocks must be defined with the
16
+ # block syntax. Adding setup or teardown instance methods defeats the purpose
17
+ # of this library.
18
+ class Test::Unit::TestCase
19
+ def self.setup(&block)
20
+ define_method :setup do
21
+ super(&block)
22
+ instance_eval(&block)
23
+ end
24
+ end
25
+
26
+ def self.teardown(&block)
27
+ define_method :teardown do
28
+ instance_eval(&block)
29
+ super(&block)
30
+ end
31
+ end
32
+
33
+ def self.context(*name, &block)
34
+ subclass = Class.new(self)
35
+ remove_tests(subclass)
36
+ subclass.class_eval(&block) if block_given?
37
+ const_set(context_name(name.join(" ")), subclass)
38
+ end
39
+
40
+ def self.test(name, &block)
41
+ define_method(test_name(name), &block)
42
+ end
43
+
44
+ class << self
45
+ alias_method :should, :test
46
+ alias_method :describe, :context
47
+ end
48
+
49
+ private
50
+
51
+ def self.context_name(name)
52
+ "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
53
+ end
54
+
55
+ def self.test_name(name)
56
+ "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
57
+ end
58
+
59
+ def self.sanitize_name(name)
60
+ name.gsub(/\W+/, ' ').strip
61
+ end
62
+
63
+ def self.remove_tests(subclass)
64
+ subclass.public_instance_methods.grep(/^test_/).each do |meth|
65
+ subclass.send(:undef_method, meth.to_sym)
66
+ end
67
+ end
68
+ end
data/test/my.watchr ADDED
@@ -0,0 +1,22 @@
1
+ puts "\n--- watchr initialized ---\n\n"
2
+
3
+ def cmd() 'ruby '; end
4
+
5
+ def run_spec(spec)
6
+ puts "Running #{spec}"
7
+ system(cmd + spec)
8
+ puts
9
+ end
10
+
11
+ watch('^test\/.*_test\.rb') {|md| run_spec(md[0]) }
12
+ watch('^lib/(.*)\.rb') {|md| run_spec("test/#{md[1]}_test.rb") }
13
+
14
+ # Ctrl-\
15
+ Signal.trap('QUIT') do
16
+ puts "\n--- Running all tests ---\n"
17
+ run_all_specs
18
+ puts
19
+ end
20
+
21
+ # Ctrl-C
22
+ Signal.trap('INT') { abort("\n") }
@@ -0,0 +1,22 @@
1
+ puts "\n--- watchr initialized ---\n\n"
2
+
3
+ def cmd() 'ruby '; end
4
+
5
+ def run_spec(spec)
6
+ puts "Running #{spec}"
7
+ system(cmd + spec)
8
+ puts
9
+ end
10
+
11
+ watch('^test\/.*_test\.rb') {|md| run_spec(md[0]) }
12
+ watch('^lib/(.*)\.rb') {|md| run_spec("test/#{md[1]}_test.rb") }
13
+
14
+ # Ctrl-\
15
+ Signal.trap('QUIT') do
16
+ puts "\n--- Running all tests ---\n"
17
+ run_all_specs
18
+ puts
19
+ end
20
+
21
+ # Ctrl-C
22
+ Signal.trap('INT') { abort("\n") }
@@ -0,0 +1,87 @@
1
+ require 'contest'
2
+ class Test::Unit::TestCase
3
+
4
+ class << self
5
+ alias_method :it, :test
6
+ end
7
+ end
8
+
9
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
10
+ require 'tweet_speak'
11
+
12
+ class TweetSpeakTest < Test::Unit::TestCase
13
+
14
+ it 'processes strings with .twittify' do
15
+ assert TweetSpeak.respond_to?(:twittify)
16
+ end
17
+
18
+ describe '.twittify' do
19
+ it 'accepts a string' do
20
+ assert_nothing_raised do
21
+ TweetSpeak.twittify('...')
22
+ end
23
+ end
24
+
25
+ it 'complains when no argument given' do
26
+ assert_raises ArgumentError do
27
+ TweetSpeak.twittify()
28
+ end
29
+ end
30
+
31
+ it 'reduces all multiple spaces to single spaces' do
32
+ assert_equal 'what on earth?', TweetSpeak.twittify('what on earth?')
33
+ end
34
+
35
+ it "changes tokens at the beginning of the string" do
36
+ assert_equal 'u cool', TweetSpeak.twittify('you cool')
37
+ end
38
+
39
+ it "changes tokens in the middle of the string" do
40
+ assert_equal 'hey u cool', TweetSpeak.twittify('hey you cool')
41
+ end
42
+
43
+ it "changes tokens at the end of the string" do
44
+ assert_equal 'hey u', TweetSpeak.twittify('hey you')
45
+ end
46
+
47
+ it "changes all instances of 'you' to 'u'" do
48
+ assert_equal 'what u doin youth?', TweetSpeak.twittify("what you doin youth?")
49
+ end
50
+
51
+ it "changes all instances of 'your' to 'ur'" do
52
+ assert_equal 'ur best', TweetSpeak.twittify("your best")
53
+ end
54
+
55
+ it "changes all instances of 'you're' to 'ur'" do
56
+ assert_equal 'ur the best', TweetSpeak.twittify("you're the best")
57
+ end
58
+
59
+ it "changes all instances of 'to' to '2'" do
60
+ assert_equal '2 be or not 2 be too?', TweetSpeak.twittify("to be or not to be too?")
61
+ end
62
+
63
+ it "changes all instances of 'are' to 'r'" do
64
+ assert_equal "r or aren't we cool?", TweetSpeak.twittify("are or aren't we cool?")
65
+ end
66
+
67
+ it "changes all instances of 'with' to 'w/'" do
68
+ assert_equal "who am I w/?", TweetSpeak.twittify("who am I with?")
69
+ end
70
+
71
+ it "changes all instances of 'without' to 'w/o'" do
72
+ assert_equal 'withholding w/o me?', TweetSpeak.twittify("withholding without me?")
73
+ end
74
+
75
+ it "changes all instances of 'because' to 'b/c'" do
76
+ assert_equal 'b/c of me?', TweetSpeak.twittify("because of me?")
77
+ end
78
+
79
+ it "changes all instances of 'before' to 'b4'" do
80
+ assert_equal 'b4 me?', TweetSpeak.twittify("before me?")
81
+ end
82
+
83
+ it "changes all instances of 'for' to '4'" do
84
+ assert_equal 'forthright 4 life', TweetSpeak.twittify("forthright for life")
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tweetspeak
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
+ - Kevin R. Barnes
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-26 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Minify your tweet without obfuscating (too much). l33t txt shorthand replacements for everyday words.
23
+ email: vinbarnes@gmail.com
24
+ executables:
25
+ - tweetspeak
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - bin/tweetspeak
32
+ - lib/tweet_speak.rb
33
+ - test/contest.rb
34
+ - test/my.watchr
35
+ - test/my.watchr.example
36
+ - test/tweet_speak_test.rb
37
+ - README.markdown
38
+ has_rdoc: true
39
+ homepage: http://github.com/vinbarnes/tweetspeak
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 59
53
+ segments:
54
+ - 1
55
+ - 8
56
+ - 6
57
+ version: 1.8.6
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Minify your tweet without obfuscating (too much).
74
+ test_files:
75
+ - test/tweet_speak_test.rb