Module: ExtendedString

Defined in:
lib/wikicloth/core_ext.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) addslashes



41
42
43
# File 'lib/wikicloth/core_ext.rb', line 41

def addslashes
  self.gsub(/['"\\\x0]/,'\\\\\0');
end


49
50
51
52
53
54
55
# File 'lib/wikicloth/core_ext.rb', line 49

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

- (Boolean) blank?



37
38
39
# File 'lib/wikicloth/core_ext.rb', line 37

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

- (Object) dump



61
62
63
64
65
# File 'lib/wikicloth/core_ext.rb', line 61

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

- (Object) last(n)



57
58
59
# File 'lib/wikicloth/core_ext.rb', line 57

def last(n)
  self[-n,n]
end

- (Object) smart_split(char)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/wikicloth/core_ext.rb', line 67

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

- (Object) to_slug



45
46
47
# File 'lib/wikicloth/core_ext.rb', line 45

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