Sha256: 8131635e09f8169642ca59c87ecff0339a7d27cc4508539fc8113c2255829030

Contents?: true

Size: 961 Bytes

Versions: 6

Compression:

Stored size: 961 Bytes

Contents

module ExtendedString

  def blank?
    respond_to?(:empty?) ? empty? : !self
  end

  def to_slug
    self.gsub(/\W+/, '-').gsub(/^-+/,'').gsub(/-+$/,'').downcase
  end

  def auto_link
    url_check = Regexp.new( '(^|[\n ])([\w]+?://[\w]+[^ \"\r\n\t<]*)', Regexp::MULTILINE | Regexp::IGNORECASE )
    www_check = Regexp.new( '(^|[\n ])((www)\.[^ \"\t\n\r<]*)', Regexp::MULTILINE | Regexp::IGNORECASE )
    self.gsub!(url_check, '\1<a href="\2">\2</a>')
    self.gsub!(www_check, '\1<a href="http://\2">\2</a>')
    to_s
  end

  def dump()
    ret = to_s
    delete!(to_s)
    ret
  end

  def smart_split(char)
    ret = []
    tmp = ""
    inside = 0
    to_s.each_char do |x|
      if x == char && inside == 0
        ret << tmp
        tmp = ""
      else
        inside += 1 if x == "[" || x == "{" || x == "<"
        inside -= 1 if x == "]" || x == "}" || x == ">"
        tmp += x
      end
    end
    ret << tmp unless tmp.empty?
    ret
  end

end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
kron4eg-wikicloth-0.1.3 lib/core_ext.rb
wikicloth-0.1.6 lib/wikicloth/core_ext.rb
wikicloth-0.1.5 lib/wikicloth/core_ext.rb
wikicloth-0.1.4 lib/wikicloth/core_ext.rb
wikicloth-0.1.3 lib/core_ext.rb
sinatra-s3-0.98 examples/wikicloth/lib/core_ext.rb