cardname 0.13.0 → 0.13.4
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/lib/cardname/danger.rb +23 -0
- data/lib/cardname/variants.rb +26 -1
- data/lib/cardname.rb +9 -43
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fec4ca9f2762b2046c7897c254af22a4b91b594ebbfa9d33f79dba177e4b17f3
|
4
|
+
data.tar.gz: 75bf8e0d3cfa758a07a6f280b433815be3e9562454446775d97c926b0ca7e3d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0e9a1ace8af5e1dbc94547bb6ff30523eb46451dcab4e7ec0f504e3ccdf0a64a89efc36279464e98f8f0f166c691ed61e881ee3b5a5c8b81f9289eb1e0c8b3b
|
7
|
+
data.tar.gz: 531c17b9e620f59a7f56dbb5bf8388b29ba21a987e49a5db0870b58d5d8ec509ad058aa5b9b723f9d4262b0138743e9cf41abd4d32740272f3a1095c50fff1fc
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Cardname
|
2
|
+
# methods that have the potential to confuse cardname cache prompt cache resets
|
3
|
+
module Danger
|
4
|
+
def self.dangerous_methods
|
5
|
+
bang_methods = String.instance_methods.select { |m| m.to_s.end_with?("!") }
|
6
|
+
%i[replace concat clear].concat bang_methods
|
7
|
+
end
|
8
|
+
|
9
|
+
dangerous_methods.each do |m|
|
10
|
+
define_method m do |*args, &block|
|
11
|
+
reset
|
12
|
+
super(*args, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def reset
|
19
|
+
self.class.reset_cache s
|
20
|
+
instance_variables.each { |var| instance_variable_set var, nil }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/cardname/variants.rb
CHANGED
@@ -10,7 +10,7 @@ class Cardname
|
|
10
10
|
.gsub(/[^#{OK4KEY_RE}]+/, "_")
|
11
11
|
.split(/_+/)
|
12
12
|
.reject(&:empty?)
|
13
|
-
.map { |key|
|
13
|
+
.map { |key| stable_key(key) }
|
14
14
|
.join("_")
|
15
15
|
end
|
16
16
|
|
@@ -35,5 +35,30 @@ class Cardname
|
|
35
35
|
def to_sym
|
36
36
|
s.to_sym
|
37
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def uninflect_method
|
42
|
+
self.class.uninflect
|
43
|
+
end
|
44
|
+
|
45
|
+
def stabilize?
|
46
|
+
self.class.stabilize
|
47
|
+
end
|
48
|
+
|
49
|
+
# Sometimes the core rule "the key's key must be itself" (called "stable" below)
|
50
|
+
# is violated. For example, it fails with singularize as uninflect method
|
51
|
+
# for Matthias -> Matthia -> Matthium
|
52
|
+
# Usually that means the name is a proper noun and not a plural.
|
53
|
+
# You can choose between two solutions:
|
54
|
+
# 1. don't uninflect if the uninflected key is not stable (stabilize = false)
|
55
|
+
# 2. uninflect until the key is stable (stabilize = true)
|
56
|
+
def stable_key name
|
57
|
+
key_one = name.send uninflect_method
|
58
|
+
key_two = key_one.send uninflect_method
|
59
|
+
return key_one unless key_one != key_two
|
60
|
+
|
61
|
+
stabilize? ? stable_key(key_two) : name
|
62
|
+
end
|
38
63
|
end
|
39
64
|
end
|
data/lib/cardname.rb
CHANGED
@@ -4,12 +4,13 @@ require "active_support/inflector"
|
|
4
4
|
require "htmlentities"
|
5
5
|
|
6
6
|
class Cardname < String
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
require "cardname/parts"
|
8
|
+
require "cardname/pieces"
|
9
|
+
require "cardname/variants"
|
10
|
+
require "cardname/contextual"
|
11
|
+
require "cardname/predicates"
|
12
|
+
require "cardname/manipulate"
|
13
|
+
require "cardname/danger"
|
13
14
|
|
14
15
|
include Parts
|
15
16
|
include Pieces
|
@@ -17,6 +18,7 @@ class Cardname < String
|
|
17
18
|
include Contextual
|
18
19
|
include Predicates
|
19
20
|
include Manipulate
|
21
|
+
include Danger
|
20
22
|
|
21
23
|
OK4KEY_RE = '\p{Word}\*'
|
22
24
|
|
@@ -68,25 +70,6 @@ class Cardname < String
|
|
68
70
|
@banned_re ||= /[#{Regexp.escape((banned_array + [joint])).join}]/
|
69
71
|
end
|
70
72
|
|
71
|
-
# Sometimes the core rule "the key's key must be itself" (called "stable" below) is violated
|
72
|
-
# eg. it fails with singularize as uninflect method for Matthias -> Matthia -> Matthium
|
73
|
-
# Usually that means the name is a proper noun and not a plural.
|
74
|
-
# You can choose between two solutions:
|
75
|
-
# 1. don't uninflect if the uninflected key is not stable (stabilize = false)
|
76
|
-
# 2. uninflect until the key is stable (stabilize = true)
|
77
|
-
def stable_key name
|
78
|
-
key_one = name.send(uninflect)
|
79
|
-
key_two = key_one.send(uninflect)
|
80
|
-
return key_one unless key_one != key_two
|
81
|
-
|
82
|
-
stabilize ? stable_key(key_two) : name
|
83
|
-
end
|
84
|
-
|
85
|
-
def dangerous_methods
|
86
|
-
bang_methods = String.instance_methods.select { |m| m.to_s.end_with?("!") }
|
87
|
-
%i[replace concat clear].concat bang_methods
|
88
|
-
end
|
89
|
-
|
90
73
|
def split_parts str
|
91
74
|
str.split(/\s*#{JOINT_RE}\s*/, -1)
|
92
75
|
end
|
@@ -110,13 +93,6 @@ class Cardname < String
|
|
110
93
|
self
|
111
94
|
end
|
112
95
|
|
113
|
-
dangerous_methods.each do |m|
|
114
|
-
define_method m do |*args, &block|
|
115
|
-
reset
|
116
|
-
super(*args, &block)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
96
|
def []= index, val
|
121
97
|
p = parts
|
122
98
|
p[index] = val
|
@@ -132,21 +108,11 @@ class Cardname < String
|
|
132
108
|
end
|
133
109
|
|
134
110
|
def == other
|
135
|
-
|
111
|
+
key ==
|
136
112
|
case
|
137
113
|
when other.respond_to?(:key) then other.key
|
138
114
|
when other.respond_to?(:to_name) then other.to_name.key
|
139
115
|
else other.to_s
|
140
116
|
end
|
141
|
-
other_key == key
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
def reset
|
147
|
-
self.class.reset_cache s
|
148
|
-
instance_variables.each do |var|
|
149
|
-
instance_variable_set var, nil
|
150
|
-
end
|
151
117
|
end
|
152
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cardname
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan McCutchen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-09-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- Rakefile
|
52
52
|
- lib/cardname.rb
|
53
53
|
- lib/cardname/contextual.rb
|
54
|
+
- lib/cardname/danger.rb
|
54
55
|
- lib/cardname/manipulate.rb
|
55
56
|
- lib/cardname/parts.rb
|
56
57
|
- lib/cardname/pieces.rb
|