more_possessive 1.0.0 → 1.0.1
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 +4 -4
- data/VERSION +1 -1
- data/lib/core_ext/string/inflections.rb +2 -2
- data/more_possessive.gemspec +3 -6
- data/rails/init.rb +1 -1
- data/test/helper.rb +1 -1
- data/test/test_possessive.rb +9 -9
- metadata +1 -5
- data/lib/possessive.rb +0 -5
- data/lib/possessive/inflections.rb +0 -16
- data/lib/possessive/inflector/inflections.rb +0 -65
- data/lib/possessive/inflector/methods.rb +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5051a8ab73904ecaf20897f8cd9cac99d2a515f4
|
|
4
|
+
data.tar.gz: 7acb284105a032edf9fa3bb70c63676e4ffb87c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 80ece20a651f701c5a26e5549e90a89e57a3acf8151ed2f9881002d11d1ffdca0bf0b6e32a98eb318f3769a333ef4b40fae5cf98f5feb09544f42e29c2cce2e6
|
|
7
|
+
data.tar.gz: 2196705c4a04ff51575236efe93215e098ea4451bb1a5c6c550b9c7ad5141efe8440ec38622a80ad4360cbd57f89e3d0d0244ac3008186941ead5de29f7524d0
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0.
|
|
1
|
+
1.0.1
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'more_possessive/inflector/methods'
|
|
2
2
|
|
|
3
3
|
class String
|
|
4
4
|
def possessive(locale = nil)
|
|
5
|
-
|
|
5
|
+
MorePossessive::Inflector.possessive(self, locale || I18n.locale)
|
|
6
6
|
end
|
|
7
7
|
end
|
data/more_possessive.gemspec
CHANGED
|
@@ -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.
|
|
5
|
+
# stub: more_possessive 1.0.1 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "more_possessive".freeze
|
|
9
|
-
s.version = "1.0.
|
|
9
|
+
s.version = "1.0.1"
|
|
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,10 +25,6 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
"Rakefile",
|
|
26
26
|
"VERSION",
|
|
27
27
|
"lib/core_ext/string/inflections.rb",
|
|
28
|
-
"lib/possessive.rb",
|
|
29
|
-
"lib/possessive/inflections.rb",
|
|
30
|
-
"lib/possessive/inflector/inflections.rb",
|
|
31
|
-
"lib/possessive/inflector/methods.rb",
|
|
32
28
|
"more_possessive.gemspec",
|
|
33
29
|
"rails/init.rb",
|
|
34
30
|
"test/helper.rb",
|
|
@@ -38,3 +34,4 @@ Gem::Specification.new do |s|
|
|
|
38
34
|
s.rubygems_version = "2.6.4".freeze
|
|
39
35
|
s.summary = "Rails plugin that lets you get a possessive form of a string for use on sites".freeze
|
|
40
36
|
end
|
|
37
|
+
|
data/rails/init.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'more_possessive'
|
data/test/helper.rb
CHANGED
data/test/test_possessive.rb
CHANGED
|
@@ -33,7 +33,7 @@ class InflectorTest < Test::Unit::TestCase
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
test "Possessive with localization" do
|
|
36
|
-
|
|
36
|
+
MorePossessive::Inflector.inflections(:de) do |inflect|
|
|
37
37
|
inflect.possessive /$/, 's'
|
|
38
38
|
inflect.possessive /(s|x|z)$/i, '\1’'
|
|
39
39
|
end
|
|
@@ -50,15 +50,15 @@ class InflectorTest < Test::Unit::TestCase
|
|
|
50
50
|
assert_equal('Fuchs’', 'Fuchs'.possessive(:de))
|
|
51
51
|
assert_equal('Fuchs’', 'Fuchs'.possessive)
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
MorePossessive::Inflector.inflections(:de) { |inflect| inflect.clear }
|
|
54
54
|
|
|
55
|
-
assert
|
|
56
|
-
assert !
|
|
55
|
+
assert MorePossessive::Inflector.inflections(:de).possessives.empty?
|
|
56
|
+
assert !MorePossessive::Inflector.inflections.possessives.empty?
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
test "clear rules" do
|
|
60
60
|
with_dup do
|
|
61
|
-
|
|
61
|
+
MorePossessive::Inflector.inflections do |inflect|
|
|
62
62
|
# ensure any data is present
|
|
63
63
|
inflect.possessive(/$/, '’s')
|
|
64
64
|
|
|
@@ -73,12 +73,12 @@ class InflectorTest < Test::Unit::TestCase
|
|
|
73
73
|
# Use this in tests what modify the state of the singleton.
|
|
74
74
|
#
|
|
75
75
|
# This helper is implemented by setting @__instance__ because in some tests
|
|
76
|
-
# there are module functions that access
|
|
76
|
+
# there are module functions that access MorePossessive::Inflector.inflections,
|
|
77
77
|
# so we need to replace the singleton itself.
|
|
78
78
|
def with_dup
|
|
79
|
-
original =
|
|
80
|
-
|
|
79
|
+
original = MorePossessive::Inflector::Inflections.instance_variable_get(:@__instance__)
|
|
80
|
+
MorePossessive::Inflector::Inflections.instance_variable_set(:@__instance__, original.dup)
|
|
81
81
|
ensure
|
|
82
|
-
|
|
82
|
+
MorePossessive::Inflector::Inflections.instance_variable_set(:@__instance__, original)
|
|
83
83
|
end
|
|
84
84
|
end
|
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.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Clubb
|
|
@@ -27,10 +27,6 @@ files:
|
|
|
27
27
|
- Rakefile
|
|
28
28
|
- VERSION
|
|
29
29
|
- lib/core_ext/string/inflections.rb
|
|
30
|
-
- lib/possessive.rb
|
|
31
|
-
- lib/possessive/inflections.rb
|
|
32
|
-
- lib/possessive/inflector/inflections.rb
|
|
33
|
-
- lib/possessive/inflector/methods.rb
|
|
34
30
|
- more_possessive.gemspec
|
|
35
31
|
- rails/init.rb
|
|
36
32
|
- test/helper.rb
|
data/lib/possessive.rb
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require '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
|
-
Possessive::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
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# Inspired by ActiveSupport::Inflector
|
|
2
|
-
module Possessive
|
|
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
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Inspired by ActiveSupport::Inflector
|
|
2
|
-
module Possessive
|
|
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
|