Sha256: 11f1fb09924e1b098dd6844491e0bd81d074c4480b01c917bed67fcd0e9bf39c

Contents?: true

Size: 851 Bytes

Versions: 8

Compression:

Stored size: 851 Bytes

Contents

require 'cgi'
require 'iconv'

class String
  my_extension("unescape_html") do
    def unescape_html
      Iconv.conv("UTF-8", 'ISO-8859-1', CGI::unescapeHTML(self))
    end
  end

  my_extension("strip_tags") do
    def strip_tags
      gsub(/<\/?[^>]*>/, "")
    end
  end

  my_extension("ext") do
    # Replace the file extension with +newext+.  If there is no extenson on
    # the string, append the new extension to the end.  If the new extension
    # is not given, or is the empty string, remove any existing extension.
    #
    # +ext+ is a user added method for the String class.
    def ext(newext='')
      return self.dup if ['.', '..'].include? self
      if newext != ''
        newext = (newext =~ /^\./) ? newext : ("." + newext)
      end
      dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || self + newext
    end
  end
end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
royw-dvdprofiler2xbmc-0.0.15 lib/string_extensions.rb
royw-dvdprofiler_collection-0.0.2 lib/string_extensions.rb
royw-dvdprofiler_collection-0.0.3 lib/string_extensions.rb
royw-dvdprofiler_collection-0.1.0 lib/string_extensions.rb
royw-imdb-0.0.21 lib/string_extensions.rb
royw-imdb-0.1.0 lib/string_extensions.rb
royw-tmdb-0.0.2 lib/string_extensions.rb
royw-tmdb-0.1.0 lib/string_extensions.rb