Module: Cardname::ClassMethods
- Included in:
- Cardname
- Defined in:
- lib/cardname/class_methods.rb
Overview
methods for the Cardname class.
Instance Method Summary collapse
-
#banned_re ⇒ Regexp
regular expression for detecting banned characters.
-
#cache ⇒ Hash
Cardname cache.
-
#new(obj) ⇒ Cardname
#new skips installation and returns a cached Cardname object when possible.
-
#nothing_banned? ⇒ Boolean
true if there are no banned characters.
-
#reset ⇒ Hash
reset Cardname cache.
-
#split_parts(str) ⇒ Array
split string on joint into parts.
Instance Method Details
#banned_re ⇒ Regexp
regular expression for detecting banned characters
40 41 42 |
# File 'lib/cardname/class_methods.rb', line 40 def banned_re @banned_re ||= /[#{Regexp.escape((banned_array + [joint])).join}]/ end |
#cache ⇒ Hash
Cardname cache. keys are strings, values are corresponding Cardname objects Note that unlike most decko/card caches, the cardname cache is process-specific and should not need to be reset even with data changes, because Cardname objects are not data-aware.
19 20 21 |
# File 'lib/cardname/class_methods.rb', line 19 def cache @cache ||= {} end |
#new(obj) ⇒ Cardname
#new skips installation and returns a cached Cardname object when possible
6 7 8 9 10 11 |
# File 'lib/cardname/class_methods.rb', line 6 def new obj return obj if obj.is_a? self.class str = stringify(obj) cache[str] ||= super(str) end |
#nothing_banned? ⇒ Boolean
true if there are no banned characters
32 33 34 35 36 |
# File 'lib/cardname/class_methods.rb', line 32 def nothing_banned? return @nothing_banned unless @nothing_banned.nil? @nothing_banned = banned_array.empty? end |
#reset ⇒ Hash
reset Cardname cache
26 27 28 |
# File 'lib/cardname/class_methods.rb', line 26 def reset @cache = {} end |
#split_parts(str) ⇒ Array
split string on joint into parts
46 47 48 |
# File 'lib/cardname/class_methods.rb', line 46 def split_parts str str.split(/\s*#{JOINT_RE}\s*/, -1) end |