cardname 0.3.13 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cardname/contextual.rb +1 -1
- data/lib/cardname/manipulate.rb +1 -1
- data/lib/cardname/parts.rb +1 -1
- data/lib/cardname/predicates.rb +5 -5
- data/lib/cardname.rb +28 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8a43b73f7cdbeeb1711642bec6713472a29444e
|
4
|
+
data.tar.gz: c99ad7d12caa1d33f1c1c98b97230085a418946d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59ed2b78bf8d651941c8bc60fe4a6f229be00bc9bce6739d3fa4eaea7fe5d4160f4f1ffdf3f7f7220405288d146ba5aec15f475850ab8defa60b00ad2a1d5d48
|
7
|
+
data.tar.gz: 151d18229b037833ed54f22fe1f5e8715d0680b2a3b88a21d837aa5248e52c4344f86e07d65d8f4ac9f41ceb003fcaf98660bb293f5aaef87ca84673d0159c3f
|
data/lib/cardname/contextual.rb
CHANGED
@@ -120,7 +120,7 @@ class Cardname
|
|
120
120
|
next if new_parts[i].present?
|
121
121
|
# following avoids recontextualizing with relative contexts.
|
122
122
|
# Eg, `+A+B+.absolute('+A')` should be +A+B, not +A+A+B.
|
123
|
-
next if new_parts.to_name.send "#{[ :start, :end ][i]}
|
123
|
+
next if new_parts.to_name.send "#{[ :start, :end ][i]}s_with_parts?", context
|
124
124
|
new_parts[i] = context
|
125
125
|
end
|
126
126
|
end
|
data/lib/cardname/manipulate.rb
CHANGED
@@ -27,7 +27,7 @@ class Cardname
|
|
27
27
|
newpiece = newpiece.to_name
|
28
28
|
|
29
29
|
return swap_part oldpiece, newpiece if oldpiece.simple?
|
30
|
-
return self unless
|
30
|
+
return self unless starts_with_parts?(oldpiece)
|
31
31
|
return newpiece if oldpiece.num_parts == num_parts
|
32
32
|
self.class.new [newpiece, self[oldpiece.num_parts..-1]].flatten
|
33
33
|
end
|
data/lib/cardname/parts.rb
CHANGED
data/lib/cardname/predicates.rb
CHANGED
@@ -12,18 +12,18 @@ class Cardname
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return true if name starts with the same parts as `prefix`
|
15
|
-
def
|
15
|
+
def starts_with_parts? *prefix
|
16
16
|
start_name = prefix.to_name
|
17
17
|
start_name == self[0, start_name.num_parts]
|
18
18
|
end
|
19
|
-
alias_method :
|
19
|
+
alias_method :start_with_parts?, :starts_with_parts?
|
20
20
|
|
21
21
|
# @return true if name ends with the same parts as `prefix`
|
22
|
-
def
|
23
|
-
end_name =
|
22
|
+
def ends_with_parts? *suffix
|
23
|
+
end_name = suffix.to_name
|
24
24
|
end_name == self[-end_name.num_parts..-1]
|
25
25
|
end
|
26
|
-
alias_method :
|
26
|
+
alias_method :end_with_parts?, :ends_with_parts?
|
27
27
|
|
28
28
|
# @return true if name has a chain of parts that equals `subname`
|
29
29
|
def include? subname
|
data/lib/cardname.rb
CHANGED
@@ -5,7 +5,6 @@ require 'active_support/inflector'
|
|
5
5
|
require 'htmlentities'
|
6
6
|
|
7
7
|
class Cardname < String
|
8
|
-
|
9
8
|
require_relative 'cardname/parts'
|
10
9
|
require_relative 'cardname/variants'
|
11
10
|
require_relative 'cardname/contextual'
|
@@ -26,7 +25,7 @@ class Cardname < String
|
|
26
25
|
:session, :stabilize
|
27
26
|
|
28
27
|
Cardname.joint = '+'
|
29
|
-
Cardname.banned_array =
|
28
|
+
Cardname.banned_array = []
|
30
29
|
Cardname.var_re = /\{([^\}]*\})\}/
|
31
30
|
Cardname.uninflect = :singularize
|
32
31
|
Cardname.stabilize = false
|
@@ -38,7 +37,7 @@ class Cardname < String
|
|
38
37
|
class << self
|
39
38
|
def new obj
|
40
39
|
return obj if obj.is_a? self.class
|
41
|
-
str = stringify
|
40
|
+
str = stringify(obj)
|
42
41
|
cached_name(str) || super(str)
|
43
42
|
end
|
44
43
|
|
@@ -59,7 +58,8 @@ class Cardname < String
|
|
59
58
|
end
|
60
59
|
|
61
60
|
def banned_re
|
62
|
-
|
61
|
+
banned_chars = (banned_array << joint).join
|
62
|
+
/[#{Regexp.escape banned_chars}]/
|
63
63
|
end
|
64
64
|
|
65
65
|
# Sometimes the core rule "the key's key must be itself" (called "stable" below) is violated
|
@@ -74,6 +74,15 @@ class Cardname < String
|
|
74
74
|
return key_one unless key_one != key_two
|
75
75
|
stabilize ? stable_key(key_two) : name
|
76
76
|
end
|
77
|
+
|
78
|
+
def dangerous_methods
|
79
|
+
bang_methods = String.instance_methods.select { |m| m.to_s.ends_with?("!") }
|
80
|
+
[:replace].concat bang_methods
|
81
|
+
end
|
82
|
+
|
83
|
+
def split_parts str
|
84
|
+
str.split(/\s*#{JOINT_RE}\s*/, -1)
|
85
|
+
end
|
77
86
|
end
|
78
87
|
|
79
88
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
@@ -94,6 +103,13 @@ class Cardname < String
|
|
94
103
|
self
|
95
104
|
end
|
96
105
|
|
106
|
+
dangerous_methods.each do |m|
|
107
|
+
define_method m do |*args, &block|
|
108
|
+
reset
|
109
|
+
super(*args, &block)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
97
113
|
def key
|
98
114
|
@key ||= part_keys.join(self.class.joint)
|
99
115
|
end
|
@@ -107,4 +123,12 @@ class Cardname < String
|
|
107
123
|
end
|
108
124
|
other_key == key
|
109
125
|
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def reset
|
130
|
+
instance_variables.each do |var|
|
131
|
+
instance_variable_set var, nil
|
132
|
+
end
|
133
|
+
end
|
110
134
|
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.
|
4
|
+
version: 0.4.0
|
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: 2018-03-
|
13
|
+
date: 2018-03-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|