Class: PinkShirt::Entities

Inherits:
Object
  • Object
show all
Defined in:
lib/pink_shirt/entities.rb

Overview

Gets rid of smart quotes, dashes and some pesky unicode

Usage

Entities.sanitize(input)

Constant Summary collapse

REPLACEMENTS =
{
  8217 => "'",   #single quote
  8216 => "'",   #left single quote
  8220 => '"',   #right double quote
  8221 => '"',   #left double quote
  8211 => "-",   #endash
  8212 => "--",  #emdash
  8230 => "...", #ellipsis
  215  => "x",   #times
  8242 => "'",   #inch
  174  => "(r)", #registered trademark
  8482 => "(tm)",# trademark
  169  => "(c)", #copyright
}

Class Method Summary collapse

Class Method Details

.sanitize(string) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/pink_shirt/entities.rb', line 22

def self.sanitize(string)
  string_chars =  string.unpack("U*")
  string_chars.map! {|x| REPLACEMENTS[x] ? REPLACEMENTS[x].unpack('U*') : x}
  string_chars.flatten
  string =  string_chars.flatten.pack('U*')
  string
end