verbs 2.0.5 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = verbs
2
2
 
3
- Conjugates most common english verbs for all persons in present and past tense (active diathesis, indicative mood). Standard and exceptional spelling rules are obeyed.
3
+ Conjugates most common english verbs for all persons in all tenses and all standard aspects (with active diathesis and indicative mood). Standard and exceptional spelling rules are obeyed.
4
4
 
5
5
  >> Verbs::Conjugator.conjugate :be, :tense => :past, :person => :second, :plurality => :singular, :aspect => :perfective
6
6
  => :were
data/Rakefile CHANGED
@@ -6,12 +6,12 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "verbs"
8
8
  gem.summary = %Q{English verb conjugation in Ruby}
9
- gem.description = %Q{Conjugates most common english verbs for all persons in present and past tense (active diathesis, indicative mood). Standard and exceptional spelling rules are obeyed.}
9
+ gem.description = %Q{Conjugates most common english verbs for all persons in all tenses and all standard aspects (with active diathesis and indicative mood). Standard and exceptional spelling rules are obeyed.}
10
10
  gem.email = "andy@rossmeissl.net"
11
11
  gem.homepage = "http://github.com/rossmeissl/verbs"
12
12
  gem.authors = ["Andy Rossmeissl"]
13
- gem.add_dependency 'andand'
14
- gem.add_dependency 'activesupport'
13
+ gem.add_dependency 'andand', '>=1.3.1'
14
+ gem.add_dependency 'activesupport', '>=2.3.4'
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
17
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.5
1
+ 2.0.8
data/lib/verbs.rb CHANGED
@@ -4,11 +4,13 @@ require 'verbs/conjugator'
4
4
  require 'verbs/conjugations'
5
5
  require 'verbs/verblike'
6
6
  require 'andand'
7
- require 'activesupport'
7
+ require 'active_support'
8
8
 
9
9
  module Verbs
10
10
  CONSONANTS = %w(b c d f g h j k l m n p q r s t v w x z)
11
11
  CONSONANT_PATTERN = "[#{CONSONANTS.join}]"
12
+ DOUBLED_CONSONANTS = %w(b c d f g h j k l m n p q r s t w z)
13
+ DOUBLED_CONSONANT_PATTERN = "[#{DOUBLED_CONSONANTS.join}]"
12
14
  VOWELS = %w(a e i o u y)
13
15
  VOWEL_PATTERN = "[#{VOWELS.join}]"
14
- end
16
+ end
@@ -1,16 +1,16 @@
1
1
  module Verbs
2
2
  module Conjugator
3
3
  extend self
4
-
4
+
5
5
  class Conjugations
6
6
  include Singleton
7
-
7
+
8
8
  attr_reader :irregulars, :single_terminal_consonants, :copulars
9
-
9
+
10
10
  def initialize
11
11
  @irregulars, @single_terminal_consonants, @copulars = {}, [], {}
12
12
  end
13
-
13
+
14
14
  def irregular(infinitive, preterite = nil, past_participle = nil, &blk)
15
15
  if block_given?
16
16
  irregular = ::Verbs::Verb.new infinitive, &blk
@@ -20,12 +20,12 @@ module Verbs
20
20
  end
21
21
  @irregulars[infinitive] = irregular
22
22
  end
23
-
23
+
24
24
  def single_terminal_consonant(infinitive)
25
25
  @single_terminal_consonants << infinitive
26
26
  end
27
27
  end
28
-
28
+
29
29
  def conjugations
30
30
  if block_given?
31
31
  yield Conjugations.instance
@@ -33,7 +33,7 @@ module Verbs
33
33
  Conjugations.instance
34
34
  end
35
35
  end
36
-
36
+
37
37
  def conjugate(infinitive, options = {})
38
38
  tense = options[:tense] || :present # present, past, future
39
39
  person = options[:person] || :third # first, second, third
@@ -41,19 +41,19 @@ module Verbs
41
41
  diathesis = options[:diathesis] || :active # active, passive
42
42
  mood = options[:mood] || :indicative # conditional, imperative, indicative, injunctive, optative, potential, subjunctive
43
43
  aspect = options[:aspect] || :habitual # perfective, habitual, progressive, perfect, prospective
44
-
44
+
45
45
  form = form_for(tense, aspect)
46
-
46
+
47
47
  conjugation = form.map { |e| resolve e, infinitive, tense, person, plurality }.join(' ').strip
48
-
48
+
49
49
  if options[:subject]
50
50
  actor = options.delete(:subject)
51
51
  actor = subject(options).humanize if actor.is_a?(TrueClass)
52
52
  end
53
-
53
+
54
54
  "#{actor} #{conjugation}".strip
55
55
  end
56
-
56
+
57
57
  def subject(options)
58
58
  case [options[:person], options[:plurality]]
59
59
  when [:first, :singular]
@@ -68,9 +68,9 @@ module Verbs
68
68
  'they'
69
69
  end
70
70
  end
71
-
71
+
72
72
  private
73
-
73
+
74
74
  def resolve(element, infinitive, tense, person, plurality)
75
75
  case element
76
76
  when String
@@ -83,11 +83,11 @@ module Verbs
83
83
  inflect element, tense, person, plurality
84
84
  end
85
85
  end
86
-
86
+
87
87
  def inflect(infinitive, inflection, person, plurality)
88
88
  send(*([inflection, infinitive, person, plurality][0, method(inflection).arity + 1]))
89
89
  end
90
-
90
+
91
91
  def present(infinitive, person, plurality)
92
92
  if verb = conjugations.irregulars[infinitive]
93
93
  conjugate_irregular(verb, :tense => :present, :person => person, :plurality => plurality)
@@ -97,7 +97,7 @@ module Verbs
97
97
  infinitive
98
98
  end
99
99
  end
100
-
100
+
101
101
  def past(infinitive, person, plurality)
102
102
  if verb = conjugations.irregulars[infinitive]
103
103
  conjugate_irregular(verb, :tense => :past, :person => person, :plurality => plurality)
@@ -105,7 +105,7 @@ module Verbs
105
105
  regular_preterite_for infinitive
106
106
  end
107
107
  end
108
-
108
+
109
109
  def present_participle(infinitive)
110
110
  if infinitive.to_s.match(/#{CONSONANT_PATTERN}#{VOWEL_PATTERN}#{CONSONANT_PATTERN}$/) and !conjugations.single_terminal_consonants.include?(infinitive)
111
111
  present_participle_with_doubled_terminal_consonant_for infinitive
@@ -119,7 +119,7 @@ module Verbs
119
119
  infinitive.to_s[0..-1].concat('ing').to_sym
120
120
  end
121
121
  end
122
-
122
+
123
123
  def past_participle(infinitive)
124
124
  if verb = conjugations.irregulars[infinitive]
125
125
  conjugate_irregular(verb, :tense => :past, :derivative => :participle)
@@ -127,10 +127,10 @@ module Verbs
127
127
  regular_preterite_for infinitive
128
128
  end
129
129
  end
130
-
130
+
131
131
  def conjugate_irregular(verb, options)
132
132
  return verb[options] if verb[options]
133
-
133
+
134
134
  tense = options[:tense]
135
135
  person = options[:person]
136
136
  plurality = options[:plurality]
@@ -146,7 +146,7 @@ module Verbs
146
146
  verb.preterite
147
147
  end
148
148
  end
149
-
149
+
150
150
  def present_third_person_singular_form_for(verb)
151
151
  infinitive = case verb
152
152
  when Verb
@@ -162,7 +162,7 @@ module Verbs
162
162
  infinitive.to_s.concat('s').to_sym
163
163
  end
164
164
  end
165
-
165
+
166
166
  def regular_preterite_for(verb)
167
167
  infinitive = case verb
168
168
  when Verb
@@ -170,7 +170,7 @@ module Verbs
170
170
  when String, Symbol
171
171
  verb.to_sym
172
172
  end
173
- if verb.to_s.match(/#{VOWEL_PATTERN}#{CONSONANT_PATTERN}$/) and !conjugations.single_terminal_consonants.include?(verb)
173
+ if verb.to_s.match(/#{CONSONANT_PATTERN}#{VOWEL_PATTERN}#{DOUBLED_CONSONANT_PATTERN}$/) and !conjugations.single_terminal_consonants.include?(verb)
174
174
  regular_preterite_with_doubled_terminal_consonant_for verb
175
175
  elsif verb.to_s.match(/#{CONSONANT_PATTERN}e$/) or verb.to_s.match(/ye$/) or verb.to_s.match(/oe$/) or verb.to_s.match(/nge$/) or verb.to_s.match(/ie$/) or verb.to_s.match(/ee$/)
176
176
  infinitive.to_s.concat('d').to_sym
@@ -180,15 +180,15 @@ module Verbs
180
180
  infinitive.to_s.concat('ed').to_sym
181
181
  end
182
182
  end
183
-
183
+
184
184
  def regular_preterite_with_doubled_terminal_consonant_for(verb)
185
185
  regular_preterite_for verb.to_s.concat(verb.to_s[-1,1]).to_sym
186
186
  end
187
-
187
+
188
188
  def present_participle_with_doubled_terminal_consonant_for(verb)
189
189
  present_participle verb.to_s.concat(verb.to_s[-1,1]).to_sym
190
190
  end
191
-
191
+
192
192
  def form_for(tense, aspect)
193
193
  form = []
194
194
  if tense == :future
data/test/test_verbs.rb CHANGED
@@ -13,44 +13,53 @@ class TestVerbs < Test::Unit::TestCase
13
13
  assert_equal 'were', Verbs::Conjugator.conjugate(:be, :tense => :past, :person => :first, :plurality => :plural, :aspect => :perfective)
14
14
  assert_equal 'were', Verbs::Conjugator.conjugate(:be, :tense => :past, :person => :third, :plurality => :plural, :aspect => :perfective)
15
15
  end
16
- def test_irregular_conjugation
17
- assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :first, :plurality => :singular, :aspect => :habitual)
18
- assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :second, :plurality => :singular, :aspect => :habitual)
19
- assert_equal 'breaks', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
20
- assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :first, :plurality => :plural, :aspect => :habitual)
21
- assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :third, :plurality => :plural, :aspect => :habitual)
22
- assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
23
- assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
24
- assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
25
- assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
26
- assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
27
- assert_equal 'has', Verbs::Conjugator.conjugate(:have, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
16
+ def test_irregular_conjugation
17
+ assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :first, :plurality => :singular, :aspect => :habitual)
18
+ assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :second, :plurality => :singular, :aspect => :habitual)
19
+ assert_equal 'breaks', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
20
+ assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :first, :plurality => :plural, :aspect => :habitual)
21
+ assert_equal 'break', Verbs::Conjugator.conjugate(:break, :tense => :present, :person => :third, :plurality => :plural, :aspect => :habitual)
22
+ assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
23
+ assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
24
+ assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
25
+ assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
26
+ assert_equal 'broke', Verbs::Conjugator.conjugate(:break, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
27
+ assert_equal 'has', Verbs::Conjugator.conjugate(:have, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
28
28
  end
29
29
  def test_irregular_conjugation_with_terminal_y
30
- assert_equal 'flies', Verbs::Conjugator.conjugate(:fly, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
31
- assert_equal 'carried', Verbs::Conjugator.conjugate(:carry, :tense => :past, :person => :third, :plurality => :singular, :aspect => :perfective)
32
- assert_equal 'stayed', Verbs::Conjugator.conjugate(:stay, :tense => :past, :person => :third, :plurality => :singular, :aspect => :perfective)
30
+ assert_equal 'flies', Verbs::Conjugator.conjugate(:fly, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
31
+ assert_equal 'carried', Verbs::Conjugator.conjugate(:carry, :tense => :past, :person => :third, :plurality => :singular, :aspect => :perfective)
32
+ assert_equal 'stayed', Verbs::Conjugator.conjugate(:stay, :tense => :past, :person => :third, :plurality => :singular, :aspect => :perfective)
33
33
  end
34
34
  def test_regular_conjugation
35
- assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :first, :plurality => :singular, :aspect => :habitual)
36
- assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :second, :plurality => :singular, :aspect => :habitual)
37
- assert_equal 'accepts', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
38
- assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :first, :plurality => :plural, :aspect => :habitual)
39
- assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :third, :plurality => :plural, :aspect => :habitual)
40
- assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
41
- assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
42
- assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
43
- assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
44
- assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
35
+ assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :first, :plurality => :singular, :aspect => :habitual)
36
+ assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :second, :plurality => :singular, :aspect => :habitual)
37
+ assert_equal 'accepts', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
38
+ assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :first, :plurality => :plural, :aspect => :habitual)
39
+ assert_equal 'accept', Verbs::Conjugator.conjugate(:accept, :tense => :present, :person => :third, :plurality => :plural, :aspect => :habitual)
40
+ assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
41
+ assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
42
+ assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
43
+ assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
44
+ assert_equal 'accepted', Verbs::Conjugator.conjugate(:accept, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
45
45
  end
46
46
  def test_regular_conjugation_with_terminal_single_consonant
47
- assert_equal 'shipped', Verbs::Conjugator.conjugate(:ship, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
47
+ assert_equal 'shipped', Verbs::Conjugator.conjugate(:ship, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
48
48
  end
49
49
  def test_regular_conjugation_with_irregular_terminal_consonant
50
- assert_equal 'abandoned', Verbs::Conjugator.conjugate(:abandon, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
50
+ assert_equal 'abandoned', Verbs::Conjugator.conjugate(:abandon, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
51
+ end
52
+ def test_regular_conjugation_with_ean_suffix
53
+ assert_equal 'cleaned', Verbs::Conjugator.conjugate(:clean, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
54
+ assert_equal 'am cleaning', Verbs::Conjugator.conjugate(:clean, :tense => :present, :person => :first, :plurality => :singular, :aspect => :progressive)
55
+ end
56
+ def test_regular_non_doubled_ending_consonant
57
+ assert_equal 'fixes', Verbs::Conjugator.conjugate(:fix, :tense => :present, :person => :third, :plurality => :singular, :aspect => :habitual)
58
+ assert_equal 'fixed', Verbs::Conjugator.conjugate(:fix, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
59
+ assert_equal 'faxed', Verbs::Conjugator.conjugate(:fix, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
51
60
  end
52
61
  def test_regular_conjugation_with_terminal_e
53
- assert_equal 'created', Verbs::Conjugator.conjugate(:create, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
62
+ assert_equal 'created', Verbs::Conjugator.conjugate(:create, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
54
63
  end
55
64
  def test_regular_conjugation_with_unusual_terminal_e
56
65
  assert_equal 'dyed', Verbs::Conjugator.conjugate(:dye, :tense => :past, :person => :first, :plurality => :singular, :aspect => :perfective)
data/verbs.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{verbs}
8
- s.version = "2.0.5"
8
+ s.version = "2.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Rossmeissl"]
12
- s.date = %q{2009-12-10}
13
- s.description = %q{Conjugates most common english verbs for all persons in present and past tense (active diathesis, indicative mood). Standard and exceptional spelling rules are obeyed.}
12
+ s.date = %q{2010-03-29}
13
+ s.description = %q{Conjugates most common english verbs for all persons in all tenses and all standard aspects (with active diathesis and indicative mood). Standard and exceptional spelling rules are obeyed.}
14
14
  s.email = %q{andy@rossmeissl.net}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -47,15 +47,15 @@ Gem::Specification.new do |s|
47
47
  s.specification_version = 3
48
48
 
49
49
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<andand>, [">= 0"])
51
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
50
+ s.add_runtime_dependency(%q<andand>, [">= 1.3.1"])
51
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
52
52
  else
53
- s.add_dependency(%q<andand>, [">= 0"])
54
- s.add_dependency(%q<activesupport>, [">= 0"])
53
+ s.add_dependency(%q<andand>, [">= 1.3.1"])
54
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
55
55
  end
56
56
  else
57
- s.add_dependency(%q<andand>, [">= 0"])
58
- s.add_dependency(%q<activesupport>, [">= 0"])
57
+ s.add_dependency(%q<andand>, [">= 1.3.1"])
58
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
59
59
  end
60
60
  end
61
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Rossmeissl
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-10 00:00:00 -05:00
12
+ date: 2010-03-29 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 1.3.1
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
@@ -30,9 +30,9 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: "0"
33
+ version: 2.3.4
34
34
  version:
35
- description: Conjugates most common english verbs for all persons in present and past tense (active diathesis, indicative mood). Standard and exceptional spelling rules are obeyed.
35
+ description: Conjugates most common english verbs for all persons in all tenses and all standard aspects (with active diathesis and indicative mood). Standard and exceptional spelling rules are obeyed.
36
36
  email: andy@rossmeissl.net
37
37
  executables: []
38
38