Module: Cardname::Variants
- Included in:
- Cardname
- Defined in:
- cardname/lib/cardname/variants.rb
Instance Method Summary collapse
-
#decoded ⇒ String
HTML Entities decoded.
-
#fully_stripped ⇒ Object
-
#safe_key ⇒ String
safe to be used in HTML as id (‘*’ and ‘+’ are not allowed), but the key is no longer unique.
-
#stripped ⇒ String
contextual elements removed.
-
#url_key ⇒ String
URI-friendly version of name.
Instance Method Details
#decoded ⇒ String
HTML Entities decoded
24 25 26 |
# File 'cardname/lib/cardname/variants.rb', line 24 def decoded @decoded ||= s.index("&") ? HTMLEntities.new.decode(s) : s end |
#fully_stripped ⇒ Object
34 35 36 |
# File 'cardname/lib/cardname/variants.rb', line 34 def fully_stripped stripped.parts.reject(&:blank?).cardname 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
18 19 20 |
# File 'cardname/lib/cardname/variants.rb', line 18 def safe_key key.tr("*", "X").tr self.class.joint, "-" end |
#stripped ⇒ String
contextual elements removed
30 31 32 |
# File 'cardname/lib/cardname/variants.rb', line 30 def stripped s.gsub(Contextual::RELATIVE_REGEXP, "").to_name end |
#url_key ⇒ String
URI-friendly version of name. retains case, underscores for space
7 8 9 10 11 12 |
# File 'cardname/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 |