Module: Cardname::Variants

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

Instance Method Summary collapse

Instance Method Details

#decodedObject



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

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



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

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
13
# File 'cardname/lib/cardname/variants.rb', line 3

def simple_key
  return "" if empty?

  decoded
    .underscore
    .gsub(/[^#{OK4KEY_RE}]+/, "_")
    .split(/_+/)
    .reject(&:empty?)
    .map { |key| self.class.stable_key(key) }
    .join("_")
end

#to_symObject



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

def to_sym
  s.to_sym
end

#url_keyObject



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

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