cardname 0.15.6 → 0.16.0

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: c51eae71caf9ca4814d780b17f04cb94d4440c149d284615d6e19e8c6c38735f
4
- data.tar.gz: 3bcf4b4ef3066dde10e66a659aa35c712200c3b1f4fb9f532984cce48d3358ec
3
+ metadata.gz: bfc02976284123b5cc7f7ecf02a312f506b617c0251521076c1f0c37ae12c9ff
4
+ data.tar.gz: 4a55923060dd3d7ef7c76535f76387701d41671e71df9169f4cbdf6f5ffcb900
5
5
  SHA512:
6
- metadata.gz: eac0575f5b9c304ca89a5d5db2ac57fcdf3a0a251ab7306dc89547995edbeb2f8b56c785470fdf15f01a15762db0b781f1b388bbd8855741699c509315dcbbde
7
- data.tar.gz: 032c0de18fca7546c980fc8a5df64ca13d53da5fb9819f84c1687f3077d9ce11d15fb224702c63e8e23d079e86935a0128d12d858d7ed2385c3af1faca392f47
6
+ metadata.gz: 40733a02910a2178c5192279f158d504654a5c1c1e7b241214dcbe63e3156b7e7d5f231c1a101b82875f3e2c5998019a3e45121b0e49763c160c95c5d15459f3
7
+ data.tar.gz: ad9350d7dc0e8f0ceec60471ae5a14bf6f04a729b0dc3e54eaf792d3a7200bd60ad73aa252a743dd9ded743120be63645ec9c4815df97d23bdb0af6b162e27a7
@@ -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
- # @return [Boolean] true if name is left or right of context
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 *args
69
- absolute(*args).to_name
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....
@@ -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
- # @return [Card::Name]
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 [True/False]
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 [True/False]
32
+ # @return [Boolean]
29
33
  def field_only?
30
- relative? && stripped.to_name.parts.reject(&:blank?).first == parts.last
34
+ relative? && stripped.parts.reject(&:blank?).first == parts.last
31
35
  end
32
36
 
33
37
  def relative_field_name tag_name
@@ -1,18 +1,21 @@
1
1
  class Cardname
2
2
  # name methods returning true/false
3
3
  module Predicates
4
- # @return [Boolean] true if name has only one part
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
- # @return [Boolean] true if name has more than one part
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
- # @return [Boolean] true unless name contains banned characters
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
- # @return [Boolean] true if name starts with the same parts as `prefix`
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
- # @return [Boolean] true if name ends with the same parts as `prefix`
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
- # @return [Boolean] true if name has a chain of parts that equals `subname`
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})/
@@ -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.15.6
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-05-02 00:00:00.000000000 Z
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.2.33
86
+ rubygems_version: 3.4.10
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: Card names without all the cards