Module: Cardname::Variants
- Included in:
- Cardname
- Defined in:
- cardname/lib/cardname/variants.rb
Instance Method Summary collapse
-
#decoded ⇒ String
-
#safe_key ⇒ String
safe to be used in HTML as id (‘*’ and ‘+’ are not allowed), but the key is no longer unique.
-
#simple_key ⇒ String
-
#url_key ⇒ String
URI-friendly version of name.
Instance Method Details
#decoded ⇒ String
36 37 38 |
# File 'cardname/lib/cardname/variants.rb', line 36 def decoded @decoded ||= s.index("&") ? HTMLEntities.new.decode(s) : s end |
#safe_key ⇒ String
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
31 32 33 |
# File 'cardname/lib/cardname/variants.rb', line 31 def safe_key key.tr("*", "X").tr self.class.joint, "-" end |
#simple_key ⇒ String
6 7 8 9 10 11 12 13 14 15 16 |
# File 'cardname/lib/cardname/variants.rb', line 6 def simple_key return "" if empty? decoded .underscore .gsub(/[^#{OK4KEY_RE}]+/, "_") .split(/_+/) .reject(&:empty?) .map { |key| stable_key(key) } .join("_") end |
#url_key ⇒ String
URI-friendly version of name. retains case, underscores for space
20 21 22 23 24 25 |
# File 'cardname/lib/cardname/variants.rb', line 20 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 |