englishext 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/englishext.rb +28 -20
  2. data/lib/englishext.rb~ +12 -7
  3. metadata +4 -3
@@ -1,6 +1,6 @@
1
1
  # A collection of English-language specific utility methods.
2
2
  module EnglishExtensions
3
- Version = '0.1.1'
3
+ Version = '0.1.2'
4
4
  end
5
5
 
6
6
  class String
@@ -54,25 +54,33 @@ class String
54
54
  # "macedonia, the former yugoslav republic of".proper_noun ->
55
55
  # "Macedonia, the Former Yugoslav Republic of"
56
56
  # "virgin islands, u.s.".proper_noun -> "Virgin Islands, U.S."
57
- def proper_noun
58
- proper_noun = ""
59
- str = self.clone
60
- while(matchIndex = str =~ /[\. \-\']/)
61
- if matchIndex == 0
62
- proper_noun += $&
63
- str = str[matchIndex+1..str.length]
64
- else
65
- word = str[0..matchIndex-1]
66
- word = word.capitalize unless [ 'and', 'the', 'of' ].index(word) != nil
67
- proper_noun += word + $&
68
- str = str[matchIndex+1..str.length]
69
- end
70
- end
71
- word = str
72
- word = word.capitalize unless [ 'and', 'the', 'of' ].index(word) != nil
73
- proper_noun += word
74
- proper_noun
75
- end
57
+ def proper_noun
58
+ proper_noun = ""
59
+ quote_seen = false
60
+ str = self.clone
61
+ while(matchIndex = str =~ /[\. \-\']/)
62
+ if matchIndex == 0
63
+ proper_noun += $&
64
+ str = str[matchIndex+1..str.length]
65
+ else
66
+ word = str[0..matchIndex-1]
67
+ unless [ 'and', 'the', 'of' ].include?(word) or
68
+ (quote_seen and word == 's')
69
+ word = word.capitalize
70
+ end
71
+ quote_seen = $& == "'"
72
+ proper_noun += word + $&
73
+ str = str[matchIndex+1..str.length]
74
+ end
75
+ end
76
+ word = str
77
+ unless [ 'and', 'the', 'of' ].include?(word) or
78
+ (quote_seen and word == 's')
79
+ word = word.capitalize
80
+ end
81
+ proper_noun += word
82
+ proper_noun
83
+ end
76
84
 
77
85
  def singular
78
86
  if self =~ /(.*)ies/
@@ -1,6 +1,6 @@
1
1
  # A collection of English-language specific utility methods.
2
2
  module EnglishExtensions
3
- Version = '0.1.0'
3
+ Version = '0.1.1'
4
4
  end
5
5
 
6
6
  class String
@@ -53,15 +53,20 @@ class String
53
53
  # "bosnia and herzegovina".proper_noun -> "Bosnia and Herzegovina"
54
54
  # "macedonia, the former yugoslav republic of".proper_noun ->
55
55
  # "Macedonia, the Former Yugoslav Republic of"
56
- # "virgin islands, u.s.".proper_noun -> "Virgin Islands, U.S."
56
+ # "virgin islands, u.s.".proper_noun -> "Virgin Islands, U.S."
57
57
  def proper_noun
58
58
  proper_noun = ""
59
59
  str = self.clone
60
- while(matchIndex = str =~ /[\. ]/)
61
- word = str[0..matchIndex-1]
62
- word = word.capitalize unless [ 'and', 'the', 'of' ].index(word) != nil
63
- proper_noun += word + $&
64
- str = str[matchIndex+1..str.length]
60
+ while(matchIndex = str =~ /[\. \-\']/)
61
+ if matchIndex == 0
62
+ proper_noun += $&
63
+ str = str[matchIndex+1..str.length]
64
+ else
65
+ word = str[0..matchIndex-1]
66
+ word = word.capitalize unless [ 'and', 'the', 'of' ].index(word) != nil
67
+ proper_noun += word + $&
68
+ str = str[matchIndex+1..str.length]
69
+ end
65
70
  end
66
71
  word = str
67
72
  word = word.capitalize unless [ 'and', 'the', 'of' ].index(word) != nil
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: englishext
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-08-20 00:00:00 -04:00
6
+ version: 0.1.2
7
+ date: 2008-05-02 00:00:00 -04:00
8
8
  summary: EnglishExtensions contains a few convenience methods for String.
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Francis Hwang
30
31
  files: