Sha256: 48e5db7c0f130efb7ac2bf3484077c39e55ff9a3b5f3df8879e3a535b824c5eb

Contents?: true

Size: 406 Bytes

Versions: 24

Compression:

Stored size: 406 Bytes

Contents

require File.dirname(__FILE__) + '/time'

class String
  def coerce
    return true if self == 'true'
    return false if self == 'false'
    coerce_try { return Time.iso8601(self) }
    coerce_try { return Integer(self) }
    coerce_try { return Float(self) }
    self
  end

  def strip_html
    gsub(/<(?:[^>'"]*|(['"]).*?\1)*>/,'')
  end

private

  def coerce_try
    yield
  rescue
    nil
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
mofo-0.2.3 ./lib/microformat/string.rb
mofo-0.2.4 ./lib/microformat/string.rb
mofo-0.2.9 ./lib/microformat/string.rb
mofo-0.2.8 ./lib/microformat/string.rb