cardname 0.15.6 → 0.16.0
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/contextual.rb +6 -14
- data/lib/cardname/fields.rb +8 -4
- data/lib/cardname/predicates.rb +18 -6
- data/lib/cardname/variants.rb +11 -13
- data/lib/cardname.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfc02976284123b5cc7f7ecf02a312f506b617c0251521076c1f0c37ae12c9ff
|
4
|
+
data.tar.gz: 4a55923060dd3d7ef7c76535f76387701d41671e71df9169f4cbdf6f5ffcb900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40733a02910a2178c5192279f158d504654a5c1c1e7b241214dcbe63e3156b7e7d5f231c1a101b82875f3e2c5998019a3e45121b0e49763c160c95c5d15459f3
|
7
|
+
data.tar.gz: ad9350d7dc0e8f0ceec60471ae5a14bf6f04a729b0dc3e54eaf792d3a7200bd60ad73aa252a743dd9ded743120be63645ec9c4815df97d23bdb0af6b162e27a7
|
data/lib/cardname/contextual.rb
CHANGED
@@ -3,7 +3,8 @@ class Cardname
|
|
3
3
|
module Contextual
|
4
4
|
RELATIVE_REGEXP = /\b_(left|right|whole|self|user|main|\d+|L*R?)\b/
|
5
5
|
|
6
|
-
#
|
6
|
+
# true if name is left or right of context
|
7
|
+
# @return [Boolean]
|
7
8
|
def child_of? context
|
8
9
|
return false unless compound?
|
9
10
|
|
@@ -28,18 +29,7 @@ class Cardname
|
|
28
29
|
!relative?
|
29
30
|
end
|
30
31
|
|
31
|
-
# contextual elements removed
|
32
32
|
# @return [String]
|
33
|
-
def stripped
|
34
|
-
s.gsub RELATIVE_REGEXP, ""
|
35
|
-
end
|
36
|
-
|
37
|
-
# +X
|
38
|
-
# @return [Boolean]
|
39
|
-
def starts_with_joint?
|
40
|
-
compound? && parts.first.empty?
|
41
|
-
end
|
42
|
-
|
43
33
|
def from *from
|
44
34
|
name_from(*from).s
|
45
35
|
end
|
@@ -47,6 +37,7 @@ class Cardname
|
|
47
37
|
# if possible, relativize name into one beginning with a "+".
|
48
38
|
# The new name must absolutize back to the correct
|
49
39
|
# original name in the context of "from"
|
40
|
+
# @return [Cardname]
|
50
41
|
def name_from *from
|
51
42
|
return self unless (remaining = remove_context(*from))
|
52
43
|
|
@@ -54,6 +45,7 @@ class Cardname
|
|
54
45
|
key == compressed.absolute_name(from).key ? compressed : self
|
55
46
|
end
|
56
47
|
|
48
|
+
# interpret contextual name
|
57
49
|
# @return [String]
|
58
50
|
def absolute context
|
59
51
|
context = (context || "").to_name
|
@@ -65,8 +57,8 @@ class Cardname
|
|
65
57
|
end
|
66
58
|
|
67
59
|
# @return [Cardname]
|
68
|
-
def absolute_name
|
69
|
-
absolute(
|
60
|
+
def absolute_name context
|
61
|
+
absolute(context).to_name
|
70
62
|
end
|
71
63
|
|
72
64
|
# 1 = left; 2= left of left; 3 = left of left of left....
|
data/lib/cardname/fields.rb
CHANGED
@@ -2,18 +2,22 @@ class Cardname
|
|
2
2
|
# Name-based "Fields" are compound names in which the right name is treated
|
3
3
|
# as an attribute of the left. (Eg MyName+address is a field of MyName)
|
4
4
|
module Fields
|
5
|
+
# @example
|
6
|
+
# "A".cardname.field_name "B" -> "A+B"
|
5
7
|
# @return [String]
|
6
8
|
def field tag_name
|
7
9
|
field_name(tag_name).s
|
8
10
|
end
|
9
11
|
|
10
|
-
# @
|
12
|
+
# @example
|
13
|
+
# "A".cardname.field_name "B" -> "A+B"
|
14
|
+
# @return [Cardname]
|
11
15
|
def field_name tag
|
12
16
|
tag = tag.to_s[1..-1] if !tag.is_a?(Symbol) && tag.to_s[0] == "+"
|
13
17
|
[self, tag].to_name
|
14
18
|
end
|
15
19
|
|
16
|
-
# @return [
|
20
|
+
# @return [Boolean]
|
17
21
|
def field_of? context
|
18
22
|
return false unless compound?
|
19
23
|
|
@@ -25,9 +29,9 @@ class Cardname
|
|
25
29
|
end
|
26
30
|
|
27
31
|
# name is relative name containing only the rightmost part
|
28
|
-
# @return [
|
32
|
+
# @return [Boolean]
|
29
33
|
def field_only?
|
30
|
-
relative? && stripped.
|
34
|
+
relative? && stripped.parts.reject(&:blank?).first == parts.last
|
31
35
|
end
|
32
36
|
|
33
37
|
def relative_field_name tag_name
|
data/lib/cardname/predicates.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
class Cardname
|
2
2
|
# name methods returning true/false
|
3
3
|
module Predicates
|
4
|
-
#
|
4
|
+
# true if name has only one part
|
5
|
+
# @return [Boolean]
|
5
6
|
def simple?
|
6
7
|
part_names if @simple.nil?
|
7
8
|
@simple
|
8
9
|
end
|
9
10
|
|
10
|
-
#
|
11
|
+
# true if name has more than one part
|
12
|
+
# @return [Boolean]
|
11
13
|
def compound?
|
12
14
|
!simple?
|
13
15
|
end
|
14
16
|
|
15
|
-
#
|
17
|
+
# true unless name contains banned characters
|
18
|
+
# @return [Boolean]
|
16
19
|
def valid?
|
17
20
|
return true if self.class.nothing_banned?
|
18
21
|
|
@@ -21,21 +24,30 @@ class Cardname
|
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
|
-
#
|
27
|
+
# +X
|
28
|
+
# @return [Boolean]
|
29
|
+
def starts_with_joint?
|
30
|
+
compound? && parts.first.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
# true if name starts with the same parts as `prefix`
|
34
|
+
# @return [Boolean]
|
25
35
|
def starts_with_parts? *prefix
|
26
36
|
start_name = prefix.to_name
|
27
37
|
start_name == self[0, start_name.num_parts]
|
28
38
|
end
|
29
39
|
alias_method :start_with_parts?, :starts_with_parts?
|
30
40
|
|
31
|
-
#
|
41
|
+
# true if name ends with the same parts as `prefix`
|
42
|
+
# @return [Boolean]
|
32
43
|
def ends_with_parts? *suffix
|
33
44
|
end_name = suffix.to_name
|
34
45
|
end_name == self[-end_name.num_parts..-1]
|
35
46
|
end
|
36
47
|
alias_method :end_with_parts?, :ends_with_parts?
|
37
48
|
|
38
|
-
#
|
49
|
+
# true if name has a chain of parts that equals `subname`
|
50
|
+
# @return [Boolean]
|
39
51
|
def include? subname
|
40
52
|
subkey = subname.to_name.key
|
41
53
|
key =~ /(^|#{JOINT_RE})#{Regexp.quote subkey}($|#{JOINT_RE})/
|
data/lib/cardname/variants.rb
CHANGED
@@ -2,19 +2,6 @@ require "htmlentities"
|
|
2
2
|
|
3
3
|
class Cardname
|
4
4
|
module Variants
|
5
|
-
# @return [String]
|
6
|
-
def simple_key
|
7
|
-
return "" if empty?
|
8
|
-
|
9
|
-
decoded
|
10
|
-
.underscore
|
11
|
-
.gsub(/[^#{OK4KEY_RE}]+/, "_")
|
12
|
-
.split(/_+/)
|
13
|
-
.reject(&:empty?)
|
14
|
-
.map { |key| stable_key(key) }
|
15
|
-
.join("_")
|
16
|
-
end
|
17
|
-
|
18
5
|
# URI-friendly version of name. retains case, underscores for space
|
19
6
|
# @return [String]
|
20
7
|
def url_key
|
@@ -32,11 +19,22 @@ class Cardname
|
|
32
19
|
key.tr("*", "X").tr self.class.joint, "-"
|
33
20
|
end
|
34
21
|
|
22
|
+
# HTML Entities decoded
|
35
23
|
# @return [String]
|
36
24
|
def decoded
|
37
25
|
@decoded ||= s.index("&") ? HTMLEntities.new.decode(s) : s
|
38
26
|
end
|
39
27
|
|
28
|
+
# contextual elements removed
|
29
|
+
# @return [String]
|
30
|
+
def stripped
|
31
|
+
s.gsub(Contextual::RELATIVE_REGEXP, "").to_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def fully_stripped
|
35
|
+
stripped.parts.reject(&:blank?).cardname
|
36
|
+
end
|
37
|
+
|
40
38
|
private
|
41
39
|
|
42
40
|
def uninflect_method
|
data/lib/cardname.rb
CHANGED
@@ -103,4 +103,17 @@ class Cardname < String
|
|
103
103
|
def generate_key
|
104
104
|
@simple ? simple_key : part_keys.join(self.class.joint)
|
105
105
|
end
|
106
|
+
|
107
|
+
# @return [String]
|
108
|
+
def simple_key
|
109
|
+
return "" if empty?
|
110
|
+
|
111
|
+
decoded
|
112
|
+
.underscore
|
113
|
+
.gsub(/[^#{OK4KEY_RE}]+/, "_")
|
114
|
+
.split(/_+/)
|
115
|
+
.reject(&:empty?)
|
116
|
+
.map { |key| stable_key(key) }
|
117
|
+
.join("_")
|
118
|
+
end
|
106
119
|
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.16.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: 2023-
|
13
|
+
date: 2023-11-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
86
|
+
rubygems_version: 3.4.10
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Card names without all the cards
|