pig_latin_translator 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0daafe32c164a89746589d3bae07e441e48c4d63
4
+ data.tar.gz: dd7be32b6bf703d57bf3fa4e69a7bf7234fbf773
5
+ SHA512:
6
+ metadata.gz: dbca2d2d28f0f9de36e2d5efaf07340d4d8ae6bc0d05bb14a452cd2c314b18eba73503ea606c3664d5a444a325af0c0773606dc7dde4d8171df359e1a709f4de
7
+ data.tar.gz: 73692717b8bdd433cd18e18427c45e23edaf2fd8d3d139e90b898fd864999cbd34729eb88789abd4a859b81e97ed40960db36a991504abe1ebca3b1de5f72739
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pig_latin_translator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joan Roig
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # PigLatinTranslator
2
+
3
+ Really simple Pig Latin translator.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pig_latin_translator'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pig_latin_translator
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ PigLatinTranslator.translate('Hello my name is Joan') # => "Ellohay ymay amenay siway Oanjay"
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/pig_latin_translator/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module PigLatinTranslator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require "pig_latin_translator/version"
2
+
3
+ module PigLatinTranslator
4
+ def self.translate(original)
5
+ original.split.map.each { |word| translate_word(word) }.join(' ')
6
+ end
7
+
8
+ private
9
+
10
+ def self.translate_word(original)
11
+ return original if original.empty?
12
+
13
+ is_first_letter_capital = original[0] == original[0].upcase
14
+ first_vowel_index = original.index(/[aeiou]/i)
15
+
16
+ if first_vowel_index == 0
17
+ translated = original[1..-1] + original[0].downcase + 'way'
18
+ elsif first_vowel_index.nil?
19
+ translated = original[1..-1] + original[0].downcase + 'ay'
20
+ else
21
+ translated = original[first_vowel_index..-1] + original[0...first_vowel_index].downcase + 'ay'
22
+ end
23
+
24
+ is_first_letter_capital ? translated.capitalize : translated
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pig_latin_translator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pig_latin_translator"
8
+ spec.version = PigLatinTranslator::VERSION
9
+ spec.authors = ["Joan Roig"]
10
+ spec.email = ["roigarderiu@gmail.com"]
11
+ spec.summary = %q{Pig Latin translator.}
12
+ spec.description = %q{Pig Latin translator.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe PigLatinTranslator do
4
+ describe '.translate' do
5
+ context 'when passed an empty string' do
6
+ it 'returns an empty string' do
7
+ expect(PigLatinTranslator.translate('')).to eq('')
8
+ end
9
+ end
10
+
11
+ context 'when called without an argument' do
12
+ it 'raises an error' do
13
+ expect { PigLatinTranslator.translate }.to raise_error(ArgumentError)
14
+ end
15
+ end
16
+
17
+ context 'when called with a word that starts with a consonant and vowel' do
18
+ it 'returns appyhay when given happy' do
19
+ expect(PigLatinTranslator.translate('happy')).to eq('appyhay')
20
+ end
21
+ end
22
+
23
+ context 'when called with a word that starts with a group of consonants' do
24
+ it 'returns oeshay when given shoes ' do
25
+ expect(PigLatinTranslator.translate('school')).to eq('oolschay')
26
+ end
27
+ end
28
+
29
+ context 'when called with a word that starts with a vowel' do
30
+ it 'returns ggeway when given egg' do
31
+ expect(PigLatinTranslator.translate('egg')).to eq('ggeway')
32
+ end
33
+
34
+ it 'returns iway when given i' do
35
+ expect(PigLatinTranslator.translate('i')).to eq('iway')
36
+ end
37
+ end
38
+
39
+ context 'when called with a word that starts with a capital letter' do
40
+ it 'returns Ggeway when given Egg' do
41
+ expect(PigLatinTranslator.translate('Egg')).to eq('Ggeway')
42
+ end
43
+ end
44
+
45
+ context 'when given a sentence with several words' do
46
+ samples = {'Hello my name is Joan' => 'Ellohay ymay amenay siway Oanjay'}
47
+ samples.each do |original, expected|
48
+ it 'returns the proper translation for the sentence' do
49
+ expect(PigLatinTranslator.translate(original)).to eq(expected)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'pig_latin_translator'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pig_latin_translator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joan Roig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ description: Pig Latin translator.
56
+ email:
57
+ - roigarderiu@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/pig_latin_translator.rb
68
+ - lib/pig_latin_translator/version.rb
69
+ - pig_latin_translator.gemspec
70
+ - spec/pig_latin_translator_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Pig Latin translator.
96
+ test_files:
97
+ - spec/pig_latin_translator_spec.rb
98
+ - spec/spec_helper.rb