Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/core_ext.rb

Overview

String class

enhanced String class

Instance Method Summary collapse

Instance Method Details

#emojifyObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tdiary/core_ext.rb', line 39

def emojify
  self.to_str.gsub(/:([a-zA-Z0-9_+-]+):/) do |match|
    emoji_alias = $1.downcase
    emoji_url = %Q[<img src='//www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/%s.png' width='20' height='20' title='%s' alt='%s' class='emoji' />]
    if emoji_alias == 'plus1' or emoji_alias == '+1'
      emoji_url % (['plus1']*3)
    elsif Emot.unicode(emoji_alias)
      emoji_url % ([CGI.escape(emoji_alias)]*3)
    else
      match
    end
  end
end


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tdiary/core_ext.rb', line 22

def make_link
  r = %r<(((http[s]{0,1}|ftp)://[\(\)%#!/0-9a-zA-Z_$@.&+-,'"*=;?:~-]+)|([0-9a-zA-Z_.-]+@[\(\)%!0-9a-zA-Z_$.&+-,'"*-]+\.[\(\)%!0-9a-zA-Z_$.&+-,'"*-]+))>
  return self.
    gsub( / /, "\001" ).
    gsub( /</, "\002" ).
    gsub( />/, "\003" ).
    gsub( /&/, '&amp;' ).
    gsub( /\"/, "\004").
    gsub( r ){ $1 == $2 ? "<a href=\"#$2\">#$2</a>" : "<a href=\"mailto:#$4\">#$4</a>" }.
    gsub( /\004/, '&quot;' ).
    gsub( /\003/, '&gt;' ).
    gsub( /\002/, '&lt;' ).
    gsub( /^\001+/ ) { $&.gsub( /\001/, '&nbsp;' ) }.
    gsub( /\001/, ' ' ).
    gsub( /\t/, '&nbsp;' * 8 )
end