cardname 0.6.8 → 0.7.0.pre

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
  SHA1:
3
- metadata.gz: 7940bcd665e6edc0328726a742900a66cf0e8fdf
4
- data.tar.gz: c3139053cb9479378d506face1cf0a4ad4f2c142
3
+ metadata.gz: a715e26a23140fa8aee5faf2591ec817f563a65a
4
+ data.tar.gz: 28651f25f3126f6c1ad79575abf59bc3a9a06a03
5
5
  SHA512:
6
- metadata.gz: c55cf5394a49c33a8cbaf57aee90684cb37c54bce8cbc1c264ec6ce4a59b3e2ab8f29f0763e34e6394690c71322390e60aac19dcf7a82ba8149b3cb9380e6d01
7
- data.tar.gz: d1da73ca34afa1d52e766862931e2e2cdad1572e594d8abdb00689feb50f6509b4e3ac55867df052edfd8c5fbada9e1080372cc08e5e4a4f5fba651ec9c71da4
6
+ metadata.gz: f2fd295ad5b0d63d9b213b5c6ed62bd69887572aae18b6cd84ac408885b84365341423cc545faf8d877de617a0591f620a2e8686ac62edeb1dfb9d07a9ea2595
7
+ data.tar.gz: 2c3aa14bdbf5072cad765a1058f36cad2f847dd4f4bbcb7d1cd5d30338bb692bc38959c7271e89fa0a14b3f26ba5876139de822abfe456644afaf2cb36f4d941
@@ -1,15 +1,15 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require 'active_support/configurable'
4
- require 'active_support/inflector'
5
- require 'htmlentities'
3
+ require "active_support/configurable"
4
+ require "active_support/inflector"
5
+ require "htmlentities"
6
6
 
7
7
  class Cardname < String
8
- require_relative 'cardname/parts'
9
- require_relative 'cardname/variants'
10
- require_relative 'cardname/contextual'
11
- require_relative 'cardname/predicates'
12
- require_relative 'cardname/manipulate'
8
+ require_relative "cardname/parts"
9
+ require_relative "cardname/variants"
10
+ require_relative "cardname/contextual"
11
+ require_relative "cardname/predicates"
12
+ require_relative "cardname/manipulate"
13
13
 
14
14
  include Parts
15
15
  include Variants
@@ -24,7 +24,7 @@ class Cardname < String
24
24
  config_accessor :joint, :banned_array, :var_re, :uninflect, :params,
25
25
  :session, :stabilize
26
26
 
27
- Cardname.joint = '+'
27
+ Cardname.joint = "+"
28
28
  Cardname.banned_array = []
29
29
  Cardname.var_re = /\{([^\}]*\})\}/
30
30
  Cardname.uninflect = :singularize
@@ -37,6 +37,7 @@ class Cardname < String
37
37
  class << self
38
38
  def new obj
39
39
  return obj if obj.is_a? self.class
40
+
40
41
  str = stringify(obj)
41
42
  cached_name(str) || super(str)
42
43
  end
@@ -57,9 +58,14 @@ class Cardname < String
57
58
  end
58
59
  end
59
60
 
61
+ def nothing_banned?
62
+ return @nothing_banned unless @nothing_banned.nil?
63
+
64
+ @nothing_banned = banned_array.empty?
65
+ end
66
+
60
67
  def banned_re
61
- banned_chars = (banned_array << joint).join
62
- /[#{Regexp.escape banned_chars}]/
68
+ @banned_re ||= /[#{Regexp.escape((banned_array + [joint])).join}]/
63
69
  end
64
70
 
65
71
  # Sometimes the core rule "the key's key must be itself" (called "stable" below) is violated
@@ -72,12 +78,13 @@ class Cardname < String
72
78
  key_one = name.send(uninflect)
73
79
  key_two = key_one.send(uninflect)
74
80
  return key_one unless key_one != key_two
81
+
75
82
  stabilize ? stable_key(key_two) : name
76
83
  end
77
84
 
78
85
  def dangerous_methods
79
86
  bang_methods = String.instance_methods.select { |m| m.to_s.ends_with?("!") }
80
- [:replace].concat bang_methods
87
+ %i[replace concat clear].concat bang_methods
81
88
  end
82
89
 
83
90
  def split_parts str
@@ -90,14 +97,14 @@ class Cardname < String
90
97
  attr_reader :key
91
98
 
92
99
  def initialize str
93
- @@cache[str] = super str.strip.encode('UTF-8')
100
+ @@cache[str] = super str.strip.encode("UTF-8")
94
101
  end
95
102
 
96
103
  def s
97
104
  @s ||= String.new self
98
105
  end
99
- alias to_s s
100
- alias to_str s
106
+ alias_method :to_s, :s
107
+ alias_method :to_str, :s
101
108
 
102
109
  def to_name
103
110
  self
@@ -110,6 +117,17 @@ class Cardname < String
110
117
  end
111
118
  end
112
119
 
120
+ # dangerous, too
121
+ def []= index, val
122
+ p = parts
123
+ p[index] = val
124
+ replace self.class.new(p)
125
+ end
126
+
127
+ def << val
128
+ replace self.class.new(parts << val)
129
+ end
130
+
113
131
  def key
114
132
  @key ||= part_keys.join(self.class.joint)
115
133
  end
@@ -127,6 +145,7 @@ class Cardname < String
127
145
  private
128
146
 
129
147
  def reset
148
+ self.class.reset_cache s
130
149
  instance_variables.each do |var|
131
150
  instance_variable_set var, nil
132
151
  end
@@ -6,6 +6,7 @@ class Cardname
6
6
  end
7
7
 
8
8
  def valid?
9
+ return true if self.class.nothing_banned?
9
10
  !parts.find do |pt|
10
11
  pt.match self.class.banned_re
11
12
  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.6.8
4
+ version: 0.7.0.pre
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: 2019-01-25 00:00:00.000000000 Z
13
+ date: 2019-03-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -76,9 +76,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '2.3'
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">="
79
+ - - ">"
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: 1.3.1
82
82
  requirements: []
83
83
  rubyforge_project:
84
84
  rubygems_version: 2.6.13