Sha256: 052fb761db34c869e12230d2b2a4bfe4d4eb54b27b43b97f68dcca5fea7bb577
Contents?: true
Size: 924 Bytes
Versions: 7
Compression:
Stored size: 924 Bytes
Contents
module Potato # Mixin module for helper methods we want to add to classes. module Helpers # Helpers for String. module String # Convert numeric and hexadecimal HTML entities to Unicode codepoints. # @return [String] def decode_entities gsub(/&#(\d+);/){[$1.to_i].pack("U*")}.gsub(/&#x([0-9a-fA-F]+);/u){[$1.to_i(16)].pack("U*")} end # Convert Unicode codepoints to numeric HTML entities. # @return [String] def encode_entities gsub(/([^ a-zA-Z0-9_.\-'",;!@#\$%^&\*\(\)\{\}\?\/\\<>=\+:])/u){"&##{$1.unpack("U*")[0]};"} end # Convert IRC formatting to tags. # @see Potato::DAmn::Client # @return [String] def to_tags gsub(/\x02(.*?)\x0F/u, '<b>\1</b>').gsub(/\x16(.*?)\x0F/u, '<i>\1</i>').gsub(/\x1F(.*?)\x0F/u, '<u>\1</u>') end end end end class String; include Potato::Helpers::String; end
Version data entries
7 entries across 7 versions & 1 rubygems