Module: ExtendedString
- Defined in:
- lib/wikicloth/core_ext.rb
Instance Method Summary collapse
- #auto_link ⇒ Object
- #blank? ⇒ Boolean
- #dump ⇒ Object
- #last(n) ⇒ Object
- #smart_split(char) ⇒ Object
- #to_slug ⇒ Object
Instance Method Details
#auto_link ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/wikicloth/core_ext.rb', line 45 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 |
#blank? ⇒ Boolean
37 38 39 |
# File 'lib/wikicloth/core_ext.rb', line 37 def blank? respond_to?(:empty?) ? empty? : !self end |
#dump ⇒ Object
57 58 59 60 61 |
# File 'lib/wikicloth/core_ext.rb', line 57 def dump() ret = to_s delete!(to_s) ret end |
#last(n) ⇒ Object
53 54 55 |
# File 'lib/wikicloth/core_ext.rb', line 53 def last(n) self[-n,n] end |
#smart_split(char) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/wikicloth/core_ext.rb', line 63 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 |
#to_slug ⇒ Object
41 42 43 |
# File 'lib/wikicloth/core_ext.rb', line 41 def to_slug self.gsub(/\W+/, '-').gsub(/^-+/,'').gsub(/-+$/,'').downcase end |