Sha256: ed11c3afc0f88a07095ab71e737adb0de36f57a7386053152b3361256f49e967
Contents?: true
Size: 923 Bytes
Versions: 2
Compression:
Stored size: 923 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]+);/){[$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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
potato-0.0.16 | lib/potato/helpers/string.rb |
potato-0.0.15 | lib/potato/helpers/string.rb |