cardname 0.13.0 → 0.13.4

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: d2d63b8ade20fc2e7a823d15562459838cf4bc352bf822ecae4175852efecd50
4
- data.tar.gz: c6f46acfcf2f84f4d3ecbd60486d264279e1896bffcea4760613f2e8086feca6
3
+ metadata.gz: fec4ca9f2762b2046c7897c254af22a4b91b594ebbfa9d33f79dba177e4b17f3
4
+ data.tar.gz: 75bf8e0d3cfa758a07a6f280b433815be3e9562454446775d97c926b0ca7e3d5
5
5
  SHA512:
6
- metadata.gz: 90509ffb908a2f04faef293d95e715129e872945f0b5878a4bde788906913d735bba6be2ee7e48751edc2c8fa38df0d662b6a961b8e9ebd6a40d9b87125b26fe
7
- data.tar.gz: d408d06a406dc6457003b90895f675ea4b14b58ba310590de7defc5c8bc08ed47aab55d63c25bedc017cee51cfcbec0820961690979a0cde581633538954b131
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
@@ -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.0
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-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