Module: Cardname::Variants

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

Instance Method Summary collapse

Instance Method Details

#decodedString

HTML Entities decoded

Returns:

  • (String)


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

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

#fully_strippedObject



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

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)


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

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

#strippedString

contextual elements removed

Returns:

  • (String)


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

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

#url_keyString

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

Returns:

  • (String)


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

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