Module: Cardname::Variants

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

Instance Method Summary collapse

Instance Method Details

#decodedObject



28
29
30
# File 'lib/cardname/variants.rb', line 28

def decoded
  @decoded ||= s.index('&') ? HTMLEntities.new.decode(s) : s
end

#safe_keyObject

safe to be used in HTML as id (‘*’ and ‘+’ are not allowed), but the key is no longer unique. For example “A-XB” and “A+*B” have the same safe_key



24
25
26
# File 'lib/cardname/variants.rb', line 24

def safe_key
  @safe_key ||= key.tr('*', 'X').tr self.class.joint, '-'
end

#simple_keyObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/cardname/variants.rb', line 3

def simple_key
  return "" if @s.empty?
  decoded
    .underscore
    .gsub(/[^#{OK4KEY_RE}]+/, '_')
    .split(/_+/)
    .reject(&:empty?)
    .map { |key| Cardname.stable_uninflect(key) }
    .join('_')
end

#to_symObject



32
33
34
# File 'lib/cardname/variants.rb', line 32

def to_sym
  s.to_sym
end

#url_keyObject



14
15
16
17
18
19
# File 'lib/cardname/variants.rb', line 14

def url_key
  @url_key ||= part_names.map do |part_name|
    stripped = part_name.decoded.gsub(/[^#{OK4KEY_RE}]+/, ' ').strip
    stripped.gsub(/[\s\_]+/, '_')
  end * self.class.joint
end