more_possessive 1.0.1 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5051a8ab73904ecaf20897f8cd9cac99d2a515f4
4
- data.tar.gz: 7acb284105a032edf9fa3bb70c63676e4ffb87c0
3
+ metadata.gz: 55c84764cabd8aab9fda60bad4f9a258511ac18b
4
+ data.tar.gz: 4d7bccb9c5998beecf6a97189af4a98aec9ef31d
5
5
  SHA512:
6
- metadata.gz: 80ece20a651f701c5a26e5549e90a89e57a3acf8151ed2f9881002d11d1ffdca0bf0b6e32a98eb318f3769a333ef4b40fae5cf98f5feb09544f42e29c2cce2e6
7
- data.tar.gz: 2196705c4a04ff51575236efe93215e098ea4451bb1a5c6c550b9c7ad5141efe8440ec38622a80ad4360cbd57f89e3d0d0244ac3008186941ead5de29f7524d0
6
+ metadata.gz: 5811820db07eecb67265fb4942260882fade98bb3563708089d390fdac81a7107a57cbfeeedbd9c36fc8d8b056c13b3257268084d09b5b234b42a80c47c146fa
7
+ data.tar.gz: 63039db2b23553274b1617c434a24ff5bf311327a33209ca52d8919c866542077c9c976a4a2c0b6dc5e6d8ad13fe8eda82af41cd30a998f758e3df13e4c48170
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -0,0 +1,5 @@
1
+ require 'more_possessive/inflector/inflections'
2
+ require 'more_possessive/inflector/methods'
3
+
4
+ require 'more_possessive/inflections'
5
+ require 'core_ext/string/inflections'
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require 'more_possessive/inflector/inflections'
3
+
4
+ #--
5
+ # Defines the standard inflection rules. These are the starting point for
6
+ # new projects and are not considered complete. The current set of inflection
7
+ # rules is frozen. This means, we do not change them to become more complete.
8
+ # This is a safety measure to keep existing applications from breaking.
9
+ #++
10
+ MorePossessive::Inflector.inflections(:en) do |inflect|
11
+ inflect.possessive(/$/, '’s')
12
+ inflect.possessive(/([^’]s)$/i, '\1’')
13
+ inflect.possessive(/(sh)$/i, '\1es’')
14
+ inflect.possessive(/(ss)$/i, '\1’s')
15
+ inflect.possessive('it', 'its')
16
+ end
@@ -0,0 +1,65 @@
1
+ # Inspired by ActiveSupport::Inflector
2
+ module MorePossessive
3
+ module Inflector
4
+ extend self
5
+
6
+ # A singleton instance of this class is yielded by Inflector.inflections,
7
+ # which can then be used to specify additional inflection rules. If passed
8
+ # an optional locale, rules for other languages can be specified. The
9
+ # default locale is <tt>:en</tt>. Only rules for English are provided.
10
+ #
11
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
12
+ # inflect.possessive /(sh)$/i, '\1es’'
13
+ # inflect.possessive /(ss)$/i, '\1’s'
14
+ # end
15
+ #
16
+ # Later rules override previous rules.
17
+ class Inflections
18
+ @__instance__ = {}
19
+
20
+ def self.instance(locale = :en)
21
+ @__instance__[locale] ||= new
22
+ end
23
+
24
+ attr_reader :possessives
25
+
26
+ def initialize
27
+ @possessives = []
28
+ end
29
+
30
+ # Specifies a possessive form of a string by a regular expression rule or
31
+ # by a string mapping. When using a regular expression based replacement,
32
+ # the normal possessive form is called after the replacement. When a
33
+ # string is used, the possessive form should be specified as desired (example:
34
+ # 'The name', not 'the_name').
35
+ #
36
+ # possessive /$/, '’s'
37
+ # possessive 'it', 'its'
38
+ def possessive(rule, replacement)
39
+ rule = /^#{rule}$/ if rule.is_a?(String)
40
+ @possessives.insert(0, [rule, replacement])
41
+ end
42
+
43
+ # Clears the loaded inflections.
44
+ def clear
45
+ @possessives = []
46
+ end
47
+ end
48
+
49
+ # Yields a singleton instance of Inflector::Inflections so you can specify
50
+ # additional inflector rules. If passed an optional locale, rules for other
51
+ # languages can be specified. If not specified, defaults to <tt>:en</tt>.
52
+ # Only rules for English are provided.
53
+ #
54
+ # Possessive::Inflector.inflections(:en) do |inflect|
55
+ # inflect.uncountable 'rails'
56
+ # end
57
+ def inflections(locale = :en)
58
+ if block_given?
59
+ yield Inflections.instance(locale)
60
+ else
61
+ Inflections.instance(locale)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,32 @@
1
+ # Inspired by ActiveSupport::Inflector
2
+ module MorePossessive
3
+ # The Inflector transforms words into their possessive form.
4
+ # The default inflections for possessive form are kept in inflections.rb.
5
+ module Inflector
6
+ extend self
7
+
8
+ # Returns the possessive form of the word in the string.
9
+ #
10
+ # If passed an optional +locale+ parameter, the possessive form of the word
11
+ # will be determined using rules defined for that language. By default,
12
+ # this parameter is set to <tt>:en</tt>.
13
+ #
14
+ # 'Brian'.possessive # => "Brian’s"
15
+ # 'Steelers'.possessive # => "Steelers’"
16
+ # 'class'.possessive # => "class’s"
17
+ # 'fish'.possessive # => "fishes’"
18
+ # 'Brian'.possessive(:de) # => "Brians"
19
+ def possessive(word, locale = :en)
20
+ result = word.to_s.dup
21
+
22
+ if word.empty?
23
+ result
24
+ else
25
+ inflections(locale).possessives.each do |(rule, replacement)|
26
+ break if result.sub!(rule, replacement)
27
+ end
28
+ result
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: more_possessive 1.0.1 ruby lib
5
+ # stub: more_possessive 1.0.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "more_possessive".freeze
9
- s.version = "1.0.1"
9
+ s.version = "1.0.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -25,6 +25,10 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/core_ext/string/inflections.rb",
28
+ "lib/more_possessive.rb",
29
+ "lib/more_possessive/inflections.rb",
30
+ "lib/more_possessive/inflector/inflections.rb",
31
+ "lib/more_possessive/inflector/methods.rb",
28
32
  "more_possessive.gemspec",
29
33
  "rails/init.rb",
30
34
  "test/helper.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: more_possessive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Clubb
@@ -27,6 +27,10 @@ files:
27
27
  - Rakefile
28
28
  - VERSION
29
29
  - lib/core_ext/string/inflections.rb
30
+ - lib/more_possessive.rb
31
+ - lib/more_possessive/inflections.rb
32
+ - lib/more_possessive/inflector/inflections.rb
33
+ - lib/more_possessive/inflector/methods.rb
30
34
  - more_possessive.gemspec
31
35
  - rails/init.rb
32
36
  - test/helper.rb