cardname 0.13.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b1d575c9f030ba1f469a778250f42972e67932b439175bdb491d2b6fac9a55b
4
- data.tar.gz: 7b0f58c98b1ad9d9c989d0b686dccb8584aaacd0d45c54ca46b09f216d5e7fe3
3
+ metadata.gz: a270d529d612496f36241b52e11910e744e4507976f5614c8c3b0afe904d3b8a
4
+ data.tar.gz: 828aa53f1b7fd74c7ddadd528136773077008a89993f8b25f1d260c561b15c22
5
5
  SHA512:
6
- metadata.gz: 3745d840bc9b35e2d5a39ff3efc1eaab31997e9d149585ded9a76d973aa5a078a78dee1df4e105156f7c9ff446c21e250449548f3a164a7b1ebabf43c4d6075f
7
- data.tar.gz: c83807b79b37e3eb08612c817397b97a7b6ce4fec562101b7cd09ea975cab1e1db64d124b7a3fc3aa90aeabf8ff48c2bbca1224bc9fa14d34e7c78a8aeca10aa
6
+ metadata.gz: d8e5baf88014f7e32331976710bc7d727d235131570c4e251e6b73846997b4b7000a9b867268f320195fe86c9d677e51c668def42c5623678a6a7c9e0d679a1b
7
+ data.tar.gz: 36fe3fa8512f8e23e27a71e76be3c037234144cb15a6d8f764c033f6b9463023b44c65e255a75960fb60cc8878fcc92f2dfc93be74d26fe4de1011f83551ccdd
@@ -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
@@ -10,7 +10,7 @@ class Cardname
10
10
  .gsub(/[^#{OK4KEY_RE}]+/, "_")
11
11
  .split(/_+/)
12
12
  .reject(&:empty?)
13
- .map { |key| self.class.stable_key(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
- require_relative "cardname/parts"
8
- require_relative "cardname/pieces"
9
- require_relative "cardname/variants"
10
- require_relative "cardname/contextual"
11
- require_relative "cardname/predicates"
12
- require_relative "cardname/manipulate"
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
- other_key =
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.2
4
+ version: 0.13.3
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-08-06 00:00:00.000000000 Z
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