indefinite_article 0.1.2 → 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.
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "indefinite_article/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "indefinite_article"
7
+ s.version = IndefiniteArticle::VERSION
8
+ s.authors = ["Andrew Rossmeissl", 'Shane Brinkman-Davis']
9
+ s.email = ["andy@rossmeissl.net"]
10
+ s.homepage = "http://github.com/rossmeissl/indefinite_article"
11
+ s.summary = %q{Adds indefinite article methods to String and Symbol}
12
+ s.description = %q{Adds indefinite article methods to String and Symbol}
13
+
14
+ s.files = [
15
+ 'indefinite_article.gemspec',
16
+ 'lib/indefinite_article.rb',
17
+ 'lib/indefinite_article/version.rb'
18
+ ]
19
+ s.require_paths = ["lib"]
20
+ s.add_dependency 'activesupport'
21
+ s.add_development_dependency 'i18n'
22
+ end
@@ -1,9 +1,33 @@
1
- require 'indefinite_article/articulated'
2
1
  require 'active_support'
3
2
  require 'active_support/core_ext/string'
4
3
 
5
4
  module IndefiniteArticle
6
- WORDS_WITH_INITIAL_VOWELS_THAT_ACT_LIKE_WORDS_WITH_INITIAL_CONSONANTS = %w(one united)
7
- INDEFINITE_ARTICLES = { :vowel => 'an', :consonant => 'a'}
8
- VOWELS = %w(a e i o u)
5
+
6
+ A_REQUIRING_PATTERNS = /^(([bcdgjkpqtuvwyz]|onc?e|onetime)$|e[uw]|uk|uni(l[^l]|[a-ko-z]))/i
7
+ AN_REQUIRING_PATTERNS = /^([aefhilmnorsx]$|hono|honest|hour|heir|[aeiou])/i
8
+ UPCASE_A_REQUIRING_PATTERNS = /^(UN$)/
9
+ UPCASE_AN_REQUIRING_PATTERNS = /^$/ #need if we decide to support acronyms like "XL" (extra-large)
10
+
11
+ def indefinite_article
12
+ first_word = to_s.split(/[- ]/).first
13
+ if (first_word[AN_REQUIRING_PATTERNS] || first_word[UPCASE_AN_REQUIRING_PATTERNS]) &&
14
+ !(first_word[A_REQUIRING_PATTERNS] || first_word[UPCASE_A_REQUIRING_PATTERNS])
15
+ 'an'
16
+ else
17
+ 'a'
18
+ end
19
+ end
20
+
21
+ def with_indefinite_article(upcase = false)
22
+ "#{upcase ? indefinite_article.humanize : indefinite_article}#{ ' ' unless self.blank? }#{self}"
23
+ end
24
+ alias :indefinitize :with_indefinite_article
25
+ end
26
+
27
+ class String
28
+ include ::IndefiniteArticle
29
+ end
30
+
31
+ class Symbol
32
+ include ::IndefiniteArticle
9
33
  end
@@ -1,3 +1,3 @@
1
1
  module IndefiniteArticle
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,153 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: indefinite_article
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
13
- - Kevin English
7
+ authors:
8
+ - Andrew Rossmeissl
9
+ - Shane Brinkman-Davis
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2012-10-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
13
+ date: 2012-12-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
21
16
  name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
- - 0
33
- version: 3.0.0
34
- - - <
35
- - !ruby/object:Gem::Version
36
- hash: 11
37
- segments:
38
- - 3
39
- - 3
40
- - 0
41
- version: 3.3.0
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
42
23
  type: :runtime
43
- version_requirements: *id001
44
- - !ruby/object:Gem::Dependency
45
- name: i18n
46
24
  prerelease: false
47
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
48
26
  none: false
49
- requirements:
50
- - - ~>
51
- - !ruby/object:Gem::Version
52
- hash: 7
53
- segments:
54
- - 0
55
- - 6
56
- - 0
57
- version: 0.6.0
58
- type: :development
59
- version_requirements: *id002
60
- - !ruby/object:Gem::Dependency
61
- name: activesupport
62
- prerelease: false
63
- requirement: &id003 !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: i18n
33
+ requirement: !ruby/object:Gem::Requirement
64
34
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 7
69
- segments:
70
- - 3
71
- - 0
72
- - 0
73
- version: 3.0.0
74
- - - <
75
- - !ruby/object:Gem::Version
76
- hash: 11
77
- segments:
78
- - 3
79
- - 3
80
- - 0
81
- version: 3.3.0
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
82
39
  type: :development
83
- version_requirements: *id003
84
- - !ruby/object:Gem::Dependency
85
- name: i18n
86
40
  prerelease: false
87
- requirement: &id004 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
88
42
  none: false
89
- requirements:
90
- - - ~>
91
- - !ruby/object:Gem::Version
92
- hash: 7
93
- segments:
94
- - 0
95
- - 6
96
- - 0
97
- version: 0.6.0
98
- type: :development
99
- version_requirements: *id004
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
100
47
  description: Adds indefinite article methods to String and Symbol
101
- email:
102
- - kenglish@gmail.com
48
+ email:
49
+ - andy@rossmeissl.net
103
50
  executables: []
104
-
105
51
  extensions: []
106
-
107
52
  extra_rdoc_files: []
108
-
109
- files:
110
- - Gemfile
111
- - LICENSE
112
- - README.rdoc
113
- - Rakefile
114
- - lib/indefinite_article/articulated.rb
115
- - lib/indefinite_article/version.rb
53
+ files:
54
+ - indefinite_article.gemspec
116
55
  - lib/indefinite_article.rb
117
- - test/test_indefinite_article.rb
118
- homepage: ""
56
+ - lib/indefinite_article/version.rb
57
+ homepage: http://github.com/rossmeissl/indefinite_article
119
58
  licenses: []
120
-
121
59
  post_install_message:
122
60
  rdoc_options: []
123
-
124
- require_paths:
61
+ require_paths:
125
62
  - lib
126
- required_ruby_version: !ruby/object:Gem::Requirement
63
+ required_ruby_version: !ruby/object:Gem::Requirement
127
64
  none: false
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
- version: "0"
135
- required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
70
  none: false
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
142
- - 0
143
- version: "0"
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
144
75
  requirements: []
145
-
146
- rubyforge_project: indefinite_article
147
- rubygems_version: 1.8.8
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.24
148
78
  signing_key:
149
79
  specification_version: 3
150
80
  summary: Adds indefinite article methods to String and Symbol
151
- test_files:
152
- - test/test_indefinite_article.rb
153
- has_rdoc:
81
+ test_files: []
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in indefinite_article.gemspec
4
- gemspec
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Andy Rossmeissl
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,18 +0,0 @@
1
- = indefinite_article
2
-
3
- Adds indefinite article methods to String and Symbol so that you can do:
4
-
5
- >> 'apple'.indefinite_article
6
- => 'an'
7
- >> 'banana'.with_indefinite_article
8
- => 'a banana'
9
-
10
- == Installation
11
-
12
- The gem is hosted at http://gemcutter.org/gems/indefinite_article
13
-
14
- gem install indefinite_article
15
-
16
- == Copyright
17
-
18
- Copyright (c) 2010 Andy Rossmeissl. See LICENSE for details.
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require 'bundler/gem_tasks'
@@ -1,33 +0,0 @@
1
- module IndefiniteArticle
2
- module Articulated
3
- def indefinite_article
4
- if ::IndefiniteArticle::WORDS_WITH_INITIAL_VOWELS_THAT_ACT_LIKE_WORDS_WITH_INITIAL_CONSONANTS.include? to_s._first_word_for_indefinite_article._first_term_for_indefinite_article.downcase
5
- ::IndefiniteArticle::INDEFINITE_ARTICLES[:consonant]
6
- elsif VOWELS.include? self.to_s.first.downcase
7
- ::IndefiniteArticle::INDEFINITE_ARTICLES[:vowel]
8
- else
9
- ::IndefiniteArticle::INDEFINITE_ARTICLES[:consonant]
10
- end
11
- end
12
-
13
- def with_indefinite_article(upcase = false)
14
- "#{upcase ? indefinite_article.humanize : indefinite_article}#{ ' ' unless self.blank? }#{self}"
15
- end
16
-
17
- def _first_word_for_indefinite_article
18
- split(' ').first
19
- end
20
-
21
- def _first_term_for_indefinite_article
22
- split('-').first
23
- end
24
- end
25
- end
26
-
27
- class String
28
- include ::IndefiniteArticle::Articulated
29
- end
30
-
31
- class Symbol
32
- include ::IndefiniteArticle::Articulated
33
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class TestIndefiniteArticle < Test::Unit::TestCase
4
- def setup
5
- end
6
- def test_active_support
7
- assert_equal 'banana'.first, 'b'
8
- end
9
- def test_indefinite_article_selection
10
- assert_equal 'a', 'banana'.indefinite_article
11
- assert_equal 'an', 'apple'.indefinite_article
12
- end
13
-
14
- def test_unusual_article_selection
15
- assert_equal 'a', 'one'.indefinite_article
16
- end
17
-
18
- def test_functionality_on_symbol
19
- assert_equal 'a', :banana.indefinite_article
20
- end
21
-
22
- def test_indefinite_article_prefix
23
- assert_equal 'a banana', 'banana'.with_indefinite_article
24
- end
25
- end