igpay_atinlay 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +3 -0
- data/Rakefile +7 -0
- data/igpay_atinlay.gemspec +20 -0
- data/lib/igpay_atinlay.rb +23 -0
- data/lib/igpay_atinlay/version.rb +3 -0
- data/test/igpay_atinlay_test.rb +60 -0
- metadata +63 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create 1.9.2@igpay_atinlay
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -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,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
|