igpay_atinlay 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.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create 1.9.2@igpay_atinlay
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in igpay_atinlay.gemspec
4
+ gemspec
@@ -0,0 +1,3 @@
1
+ igpay_atinlay is a gem that adds the ability for a string to translate itself to
2
+ [Pig Latin](http://en.wikipedia.org/wiki/PigLatin). We have added a few additional rules to those on
3
+ wikipedia.
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new do |i|
5
+ i.test_files = FileList['test/*_test.rb']
6
+ i.verbose = true
7
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "igpay_atinlay/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "igpay_atinlay"
7
+ s.version = IgpayAtinlay::VERSION
8
+ s.authors = ["Michael Wynholds"]
9
+ s.email = ["mike@carbonfive.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Adds String.to_pig_latin}
12
+ s.description = %q{Pig Latin converter mixed in to String}
13
+
14
+ s.rubyforge_project = "igpay_atinlay"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,23 @@
1
+ String.class_eval do
2
+ def to_pig_latin
3
+ self.split(/(\-|\s+)/).collect do |word|
4
+ if ! word.pig_latin_friendly?
5
+ word
6
+ else
7
+ word.match /^(qu|[^aeiou]*)(.+?)([^a-z]*)$/i do |m|
8
+ first, middle, punc = m[1], m[2], m[3]
9
+ middle.capitalize! if first =~ /^[A-Z]/
10
+ first.downcase!
11
+ last = (middle + first == 'a' ? 'y' : 'ay')
12
+ middle + first + last + punc
13
+ end
14
+ end
15
+ end.join
16
+ end
17
+
18
+ protected
19
+
20
+ def pig_latin_friendly?
21
+ self =~ /^[a-z']+[^a-z0-9]*$/i
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module IgpayAtinlay
2
+ VERSION = "1.0"
3
+ end
@@ -0,0 +1,60 @@
1
+ require 'minitest/autorun'
2
+ require 'igpay_atinlay'
3
+
4
+ class IglatinpayTest < MiniTest::Spec
5
+ describe 'single word' do
6
+ it 'appends "ay" to the end of the word' do
7
+ 'hello'.to_pig_latin.must_equal 'ellohay'
8
+ end
9
+ end
10
+ describe 'multiple words' do
11
+ it 'splits the words on whitespace' do
12
+ 'hello world'.to_pig_latin.must_equal 'ellohay orldway'
13
+ end
14
+ end
15
+ describe 'capitalization' do
16
+ it 'keeps the first letter capitalized' do
17
+ 'Hello World'.to_pig_latin.must_equal 'Ellohay Orldway'
18
+ end
19
+ end
20
+ describe 'punctuation at the end of a word' do
21
+ it 'keeps any punctuation at the end' do
22
+ 'Hello, World!!'.to_pig_latin.must_equal 'Ellohay, Orldway!!'
23
+ end
24
+ end
25
+ describe 'punctuation within a word' do
26
+ it 'keeps punctuation within the word' do
27
+ "Mike's computer".to_pig_latin.must_equal "Ike'smay omputercay"
28
+ end
29
+ end
30
+ describe 'multiple consonants at the beginning of a word' do
31
+ it 'keeps consonants at the beginning of a word together' do
32
+ 'Quick brown fox'.to_pig_latin.must_equal 'Ickquay ownbray oxfay'
33
+ end
34
+ end
35
+ describe 'vowels at the beginning of a word' do
36
+ it 'keeps vowels at the beginning of the word intact' do
37
+ 'eat apples'.to_pig_latin.must_equal 'eatay applesay'
38
+ end
39
+ end
40
+ describe 'whitespace' do
41
+ it 'splits on all whitespace and keeps it intact' do
42
+ 'Hello... world!'.to_pig_latin.must_equal 'Ellohay... orldway!'
43
+ end
44
+ end
45
+ describe 'non-word words' do
46
+ it 'does not translate non-word words' do
47
+ 'hello 12345 abc123 ab123cd world'.to_pig_latin.must_equal 'ellohay 12345 abc123 ab123cd orldway'
48
+ end
49
+ end
50
+ describe 'edge cases' do
51
+ it 'converts "a" to "ay", not "aay"' do
52
+ 'a'.to_pig_latin.must_equal 'ay'
53
+ end
54
+ end
55
+ describe 'hyphens' do
56
+ it 'splits hyphenated words up' do
57
+ 'rob is a bad-ass'.to_pig_latin.must_equal 'obray isay ay adbay-assay'
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: igpay_atinlay
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "1.0"
6
+ platform: ruby
7
+ authors:
8
+ - Michael Wynholds
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-15 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: Pig Latin converter mixed in to String
17
+ email:
18
+ - mike@carbonfive.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - .gitignore
27
+ - .rvmrc
28
+ - Gemfile
29
+ - README.md
30
+ - Rakefile
31
+ - igpay_atinlay.gemspec
32
+ - lib/igpay_atinlay.rb
33
+ - lib/igpay_atinlay/version.rb
34
+ - test/igpay_atinlay_test.rb
35
+ homepage: ""
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ requirements: []
56
+
57
+ rubyforge_project: igpay_atinlay
58
+ rubygems_version: 1.7.2
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Adds String.to_pig_latin
62
+ test_files:
63
+ - test/igpay_atinlay_test.rb