plural 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-version
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - jruby-19mode
7
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Andrew Stewart
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # Plural
2
+
3
+ [![Build Status](https://travis-ci.org/stewart/plural.png)](https://travis-ci.org/stewart/plural)
4
+
5
+ A gem for pluralizing words.
6
+
7
+ ## Support
8
+
9
+ Plural should work with any Ruby using the MRI 1.9 syntax, including MRI 2.0.0,
10
+ JRuby, and Rubinius.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'plural'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```shell
23
+ $ bundle install
24
+ ```
25
+
26
+ Or install it yourself as:
27
+
28
+ ```shell
29
+ $ gem install plural
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ "post".plural
36
+ # => "posts"
37
+
38
+ "octopus".plural
39
+ # => "octopi"
40
+
41
+ "sheep".plural
42
+ # => "sheep"
43
+
44
+ "words".plural
45
+ # => "words"
46
+
47
+ "CamelOctopus".plural
48
+ # => "CamelOctopi"
49
+ ```
50
+
51
+ ## Development
52
+
53
+ Want to help out?
54
+
55
+ First, clone the repo and run the test suite:
56
+
57
+ ```shell
58
+ git clone git://github.com/stewart/plural.git
59
+ cd plural
60
+ bundle
61
+ rake
62
+ ```
63
+
64
+ The test cases are taken direct from ActiveSupport.
65
+
66
+ Then:
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ task default: :spec
6
+
7
+ RSpec::Core::RakeTask.new :spec
8
+
9
+ desc 'Open an irb session reploaded with the plural library'
10
+ task :console do
11
+ sh 'irb -Ilib -rplural'
12
+ end
@@ -0,0 +1,63 @@
1
+ require "plural/version"
2
+
3
+ module Plural
4
+ def self.rules
5
+ @rules ||= [
6
+ [/(z)ombies$/i, "\\1ombies"],
7
+ [/(z)ombie$/i, "\\1ombies"],
8
+ [/k(?i)ine$/, "kine"],
9
+ [/K(?i)ine$/, "Kine"],
10
+ [/c(?i)ow$/, "kine"],
11
+ [/C(?i)ow$/, "Kine"],
12
+ [/(m)oves$/i, "\\1oves"],
13
+ [/(m)ove$/i, "\\1oves"],
14
+ [/(s)exes$/i, "\\1exes"],
15
+ [/(s)ex$/i, "\\1exes"],
16
+ [/(c)hildren$/i, "\\1hildren"],
17
+ [/(c)hild$/i, "\\1hildren"],
18
+ [/(m)en$/i, "\\1en"],
19
+ [/(m)an$/i, "\\1en"],
20
+ [/(p)eople$/i, "\\1eople"],
21
+ [/(p)erson$/i, "\\1eople"],
22
+ [/(quiz)$/i, "\\1zes"],
23
+ [/^(oxen)$/i, "\\1"],
24
+ [/^(ox)$/i, "\\1en"],
25
+ [/^(m|l)ice$/i, "\\1ice"],
26
+ [/^(m|l)ouse$/i, "\\1ice"],
27
+ [/(matr|vert|ind)(?:ix|ex)$/i, "\\1ices"],
28
+ [/(x|ch|ss|sh)$/i, "\\1es"],
29
+ [/([^aeiouy]|qu)y$/i, "\\1ies"],
30
+ [/(hive)$/i, "\\1s"],
31
+ [/(?:([^f])fe|([lr])f)$/i, "\\1\\2ves"],
32
+ [/sis$/i, "ses"],
33
+ [/([ti])a$/i, "\\1a"],
34
+ [/([ti])um$/i, "\\1a"],
35
+ [/(buffal|tomat)o$/i, "\\1oes"],
36
+ [/(bu)s$/i, "\\1ses"],
37
+ [/(alias|status)$/i, "\\1es"],
38
+ [/(octop|vir)i$/i, "\\1i"],
39
+ [/(octop|vir)us$/i, "\\1i"],
40
+ [/^(ax|test)is$/i, "\\1es"],
41
+ [/s$/i, "s"],
42
+ [/$/, "s"]
43
+ ]
44
+ end
45
+
46
+ def self.uncountables
47
+ @uncountables ||= %w(equipment information rice money
48
+ species series fish sheep jeans police)
49
+ end
50
+ end
51
+
52
+ class String
53
+ def plural
54
+ result = self.dup
55
+
56
+ if self.empty? || Plural.uncountables.any? { |i| result =~ /\b#{i}\Z/i }
57
+ result
58
+ else
59
+ Plural.rules.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
60
+ result
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Plural
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path '../lib/plural/version', __FILE__
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "plural"
6
+ spec.version = Plural::VERSION
7
+ spec.authors = ["Andrew Stewart"]
8
+ spec.email = ["andrew@averagestudios.com"]
9
+ spec.description = %q{A gem to pluralize words.}
10
+ spec.summary = %q{A gem to pluralize words.}
11
+ spec.homepage = "https://github.com/stewart/plural"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rspec", "~> 2.13.0"
22
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'lib/singular_to_plural'
3
+
4
+ describe String do
5
+ describe ".plural" do
6
+ SingularToPlural.each do |singular, plural|
7
+ it "pluralizes #{singular}" do
8
+ expect(singular.plural).to eq plural
9
+ end
10
+ end
11
+
12
+ SingularToPlural.each do |singular, plural|
13
+ it "doesn't pluralize #{plural}" do
14
+ expect(plural.plural).to eq plural
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,108 @@
1
+ SingularToPlural = {
2
+ "search" => "searches",
3
+ "switch" => "switches",
4
+ "fix" => "fixes",
5
+ "box" => "boxes",
6
+ "process" => "processes",
7
+ "address" => "addresses",
8
+ "case" => "cases",
9
+ "stack" => "stacks",
10
+ "wish" => "wishes",
11
+ "fish" => "fish",
12
+ "jeans" => "jeans",
13
+ "funky jeans" => "funky jeans",
14
+ "my money" => "my money",
15
+
16
+ "category" => "categories",
17
+ "query" => "queries",
18
+ "ability" => "abilities",
19
+ "agency" => "agencies",
20
+ "movie" => "movies",
21
+
22
+ "archive" => "archives",
23
+
24
+ "index" => "indices",
25
+
26
+ "wife" => "wives",
27
+ "safe" => "saves",
28
+ "half" => "halves",
29
+
30
+ "move" => "moves",
31
+
32
+ "salesperson" => "salespeople",
33
+ "person" => "people",
34
+
35
+ "spokesman" => "spokesmen",
36
+ "man" => "men",
37
+ "woman" => "women",
38
+
39
+ "basis" => "bases",
40
+ "diagnosis" => "diagnoses",
41
+ "diagnosis_a" => "diagnosis_as",
42
+
43
+ "datum" => "data",
44
+ "medium" => "media",
45
+ "stadium" => "stadia",
46
+ "analysis" => "analyses",
47
+
48
+ "node_child" => "node_children",
49
+ "child" => "children",
50
+
51
+ "experience" => "experiences",
52
+ "day" => "days",
53
+
54
+ "comment" => "comments",
55
+ "foobar" => "foobars",
56
+ "newsletter" => "newsletters",
57
+
58
+ "old_news" => "old_news",
59
+ "news" => "news",
60
+
61
+ "series" => "series",
62
+ "species" => "species",
63
+
64
+ "quiz" => "quizzes",
65
+
66
+ "perspective" => "perspectives",
67
+
68
+ "ox" => "oxen",
69
+ "photo" => "photos",
70
+ "buffalo" => "buffaloes",
71
+ "tomato" => "tomatoes",
72
+ "dwarf" => "dwarves",
73
+ "elf" => "elves",
74
+ "information" => "information",
75
+ "equipment" => "equipment",
76
+ "bus" => "buses",
77
+ "status" => "statuses",
78
+ "status_code" => "status_codes",
79
+ "mouse" => "mice",
80
+
81
+ "louse" => "lice",
82
+ "house" => "houses",
83
+ "octopus" => "octopi",
84
+ "virus" => "viri",
85
+ "alias" => "aliases",
86
+ "portfolio" => "portfolios",
87
+
88
+ "vertex" => "vertices",
89
+ "matrix" => "matrices",
90
+ "matrix_fu" => "matrix_fus",
91
+
92
+ "axis" => "axes",
93
+ "testis" => "testes",
94
+ "crisis" => "crises",
95
+
96
+ "rice" => "rice",
97
+ "shoe" => "shoes",
98
+
99
+ "horse" => "horses",
100
+ "prize" => "prizes",
101
+ "edge" => "edges",
102
+
103
+ "cow" => "kine",
104
+ "database" => "databases",
105
+
106
+ "|ice" => "|ices",
107
+ "|ouse" => "|ouses"
108
+ }
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Plural do
4
+ it "has a version number" do
5
+ expect(Plural::VERSION).to be_a String
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'plural'
2
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plural
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Stewart
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ none: false
21
+ name: bundler
22
+ type: :development
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.3'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ none: false
37
+ name: rake
38
+ type: :development
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ~>
50
+ - !ruby/object:Gem::Version
51
+ version: 2.13.0
52
+ none: false
53
+ name: rspec
54
+ type: :development
55
+ prerelease: false
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: 2.13.0
61
+ none: false
62
+ description: A gem to pluralize words.
63
+ email:
64
+ - andrew@averagestudios.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .travis.yml
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - lib/plural.rb
76
+ - lib/plural/version.rb
77
+ - plural.gemspec
78
+ - spec/lib/plural_spec.rb
79
+ - spec/lib/singular_to_plural.rb
80
+ - spec/lib/version_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: https://github.com/stewart/plural
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ none: false
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ none: false
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.23
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: A gem to pluralize words.
107
+ test_files:
108
+ - spec/lib/plural_spec.rb
109
+ - spec/lib/singular_to_plural.rb
110
+ - spec/lib/version_spec.rb
111
+ - spec/spec_helper.rb