inflectious 0.1.0 → 0.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/inflectious.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{inflectious}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Atkins"]
@@ -23,7 +23,12 @@ Gem::Specification.new do |s|
23
23
  "README.rdoc",
24
24
  "Rakefile",
25
25
  "VERSION",
26
+ "inflectious.gemspec",
27
+ "init.rb",
28
+ "lib/inflections.rb",
26
29
  "lib/inflectious.rb",
30
+ "lib/inflectious/inflector.rb",
31
+ "lib/inflectious/string.rb",
27
32
  "test/helper.rb",
28
33
  "test/test_inflectious.rb"
29
34
  ]
data/init.rb CHANGED
@@ -1,2 +1 @@
1
- require 'inflectious'
2
- require 'inflections'
1
+ require 'inflectious'
data/lib/inflections.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  ActiveSupport::Inflector.inflections do |inflect|
2
- inflect.gerund /ing$/i, '\0'
3
- inflect.gerund /([^aeiou]|[aeiou]{2})[^aeiou]$/i, '\0ing'
4
- inflect.gerund /(\w*[^aeiou])e$/i, '\1ing'
5
- inflect.gerund /[aeiou]([^aeiou])$/i, '\0\1ing'
2
+ inflect.stem(/(.*[^aeiou])e$/i, '\1')
3
+ inflect.stem(/[aeiou]([^aeiou])$/i, '\0\1')
4
+ inflect.stem(/[aeiou]{2}[^aeiou]$/i, '\0')
6
5
  end
data/lib/inflectious.rb CHANGED
@@ -1,23 +1,6 @@
1
- module ActiveSupport
2
- module Inflector
3
- class Inflections
4
- attr_reader :gerunds
1
+ module Inflectious
2
+ end
5
3
 
6
- def gerunds
7
- @gerunds ||= []
8
- end
9
-
10
- end
11
-
12
- def gerundize(word)
13
- result = word.to_s.dup
14
- if word.empty?
15
- result
16
- else
17
- inflections.gerunds.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
18
- result == word ? word + 'ing' : result
19
- end
20
- end
21
-
22
- end
23
- end
4
+ require 'inflectious/inflector'
5
+ require 'inflections'
6
+ require 'inflectious/string'
@@ -0,0 +1,52 @@
1
+ module ActiveSupport
2
+ module Inflector
3
+ class Inflections
4
+ attr_reader :gerunds
5
+
6
+ def stems
7
+ @stems ||= []
8
+ end
9
+
10
+ def stem(rule, replacement)
11
+ @uncountables.delete(rule) if rule.is_a?(String)
12
+ @uncountables.delete(replacement)
13
+ stems.insert(0, [rule, replacement])
14
+ end
15
+
16
+ end
17
+
18
+ def adjectivize(word)
19
+ word.match(/y$/) ? word : stem(word) + 'y'
20
+ end
21
+
22
+ def doerize(word)
23
+ stem(word) + 'er'
24
+ end
25
+
26
+ def gerundize(word)
27
+ stem(word) + 'ing'
28
+ end
29
+
30
+ def participlize(word)
31
+ stem(word) + 'ed'
32
+ end
33
+
34
+ def superlativize(word, options = {})
35
+ if options[:adjective]
36
+ stem(word) + 'est'
37
+ else
38
+ word.gsub(/y$/, "i") + 'est'
39
+ end
40
+ end
41
+
42
+ def stem(word)
43
+ result = word.to_s.dup
44
+ if word.empty?
45
+ result
46
+ else
47
+ inflections.stems.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
48
+ result
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ class String
2
+ def inflections
3
+ inflections_with_names.collect(&:first)
4
+ end
5
+
6
+ def inflections_with_names
7
+ returning out = [] do
8
+ out << [self, "self"]
9
+ out << [singularize, "singularize"]
10
+ out << [pluralize, "pluralize"]
11
+ out << [participlize, "participlize"]
12
+ out << [gerundize, "gerundize"]
13
+ out << [gerundize.pluralize, "gerundize plural"]
14
+ out << [doerize, "doerize"]
15
+ out << [doerize.pluralize, "doerize plural"]
16
+ out << [adjectivize, "adjectivize"]
17
+ out << [superlativize, "superlativize"]
18
+ out << [superlativize(:adjective => true), "superlativize adjective"]
19
+ end
20
+ end
21
+
22
+ def adjectivize
23
+ ActiveSupport::Inflector.adjectivize(self)
24
+ end
25
+
26
+ def doerize
27
+ ActiveSupport::Inflector.doerize(self)
28
+ end
29
+
30
+ def gerundize
31
+ ActiveSupport::Inflector.gerundize(self)
32
+ end
33
+
34
+ def participlize
35
+ ActiveSupport::Inflector.participlize(self)
36
+ end
37
+
38
+ def superlativize(options={})
39
+ ActiveSupport::Inflector.superlativize(self, options)
40
+ end
41
+
42
+ def stem
43
+ ActiveSupport::Inflector.stem(self)
44
+ end
45
+ end
data/test/helper.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+
4
+ require 'active_support'
5
+ require 'lib/inflectious.rb'
6
+
3
7
  begin
4
8
  Bundler.setup(:default, :development)
5
9
  rescue Bundler::BundlerError => e
@@ -7,12 +11,12 @@ rescue Bundler::BundlerError => e
7
11
  $stderr.puts "Run `bundle install` to install missing gems"
8
12
  exit e.status_code
9
13
  end
14
+
10
15
  require 'test/unit'
11
16
  require 'shoulda'
12
17
 
13
18
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
19
  $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'inflectious'
16
20
 
17
21
  class Test::Unit::TestCase
18
22
  end
@@ -1,7 +1,16 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestInflectious < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ should "gerundize regular word" do
5
+ assert_equal ActiveSupport::Inflector.gerundize("walk"), "walking"
6
+ end
7
+ should "gerundize word ending with a vowel" do
8
+ assert_equal ActiveSupport::Inflector.gerundize("grate"), "grating"
9
+ end
10
+ should "gerundize word ending with vowel consonant" do
11
+ assert_equal ActiveSupport::Inflector.gerundize("sit"), "sitting"
12
+ end
13
+ should "gerundize word ending with vowel vowel consonant" do
14
+ assert_equal ActiveSupport::Inflector.gerundize("greet"), "greeting"
6
15
  end
7
16
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inflectious
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Atkins
@@ -128,6 +128,8 @@ files:
128
128
  - init.rb
129
129
  - lib/inflections.rb
130
130
  - lib/inflectious.rb
131
+ - lib/inflectious/inflector.rb
132
+ - lib/inflectious/string.rb
131
133
  - test/helper.rb
132
134
  - test/test_inflectious.rb
133
135
  has_rdoc: true