Module: Cardname::Variants

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

Overview

some useful variants of card names

Instance Method Summary collapse

Instance Method Details

#decodedString

HTML Entities decoded

Returns:

  • (String)


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

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

#fully_strippedObject



35
36
37
# File 'lib/cardname/variants.rb', line 35

def fully_stripped
  stripped.parts.reject(&:blank?).cardname
end

#safe_keyString

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

Returns:

  • (String)


19
20
21
# File 'lib/cardname/variants.rb', line 19

def safe_key
  key.tr("*", "X").tr self.class.joint, "-"
end

#strippedString

contextual elements removed

Returns:

  • (String)


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

def stripped
  s.gsub(Contextual::RELATIVE_REGEXP, "").to_name
end

#url_keyString

URI-friendly version of name. retains case, underscores for space

Returns:

  • (String)


8
9
10
11
12
13
# File 'lib/cardname/variants.rb', line 8

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