Module: Cardname::ClassMethods

Included in:
Cardname
Defined in:
cardname/lib/cardname/class_methods.rb

Overview

methods for the Cardname class.

Instance Method Summary collapse

Instance Method Details

#banned_reRegexp

regular expression for detecting banned characters

Returns:

  • (Regexp)
[View source]

40
41
42
# File 'cardname/lib/cardname/class_methods.rb', line 40

def banned_re
  @banned_re ||= /[#{Regexp.escape((banned_array + [joint])).join}]/
end

#cacheHash

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.

Returns:

  • (Hash)
[View source]

19
20
21
# File 'cardname/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

Returns:

[View source]

6
7
8
9
10
11
# File 'cardname/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

Returns:

  • (Boolean)
[View source]

32
33
34
35
36
# File 'cardname/lib/cardname/class_methods.rb', line 32

def nothing_banned?
  return @nothing_banned unless @nothing_banned.nil?

  @nothing_banned = banned_array.empty?
end

#resetHash

reset Cardname cache

Returns:

  • (Hash)

See Also:

[View source]

26
27
28
# File 'cardname/lib/cardname/class_methods.rb', line 26

def reset
  @cache = {}
end

#split_parts(str) ⇒ Array

split string on joint into parts

Returns:

  • (Array)
[View source]

46
47
48
# File 'cardname/lib/cardname/class_methods.rb', line 46

def split_parts str
  str.split(/\s*#{JOINT_RE}\s*/, -1)
end