class Emoji2020
Public Class Methods
new(obj=nil, debug: false)
click to toggle source
# File lib/emoji2020.rb, line 1835 def initialize(obj=nil, debug: false) a = EMOJI.strip.gsub(/\s+#[^\n]+/,'').gsub(/^\n/,'').lines\ .map {|x| x.chomp.lstrip.split(/ /,2).reverse} h = a.map {|key, value| [key.downcase.gsub(/\W+/,'_').to_sym, value]}.to_h puts 'h: ' + h.inspect if debug @s = case obj.class.to_s when 'Symbol' keyword = obj r = h[keyword] r ? r : h[find(keyword)] when 'String' s = obj s.gsub!(/:(\w+):/) do |x| emoji = Emoji2020.new(($1).to_sym).to_s emoji ? emoji : ':' + x + ':' end puts 's: ' + s.inspect if debug s end end
Public Instance Methods
find(keyword)
click to toggle source
accepts a search keyword and returns the markdown name of the emoji
e.g. find('sunrise') #=> :sunrise:
# File lib/emoji2020.rb, line 1870 def find(keyword) r = search(keyword.to_s) return unless r.any? line = r.first _, title = line.strip.gsub(/\s+#[^\n]+/,'').split(/ /,2) title.downcase.gsub(/\W+/,'_').to_sym end
search(keyword)
click to toggle source
accepts a search keyword and returns a raw listing of emoji search results
# File lib/emoji2020.rb, line 1884 def search(keyword) a = keyword.split(/[ _]/) a2 = a.map do |x| r = EMOJI.lines.grep /\b#{x}\b/i if r.any? then r else EMOJI.lines.grep /#{x}/i end end a2.inject(:&) end
to_a()
click to toggle source
returns decimal value of each Unicode byte sequence used to
construct the emoji
# File lib/emoji2020.rb, line 1907 def to_a() @s.unpack('U*') end
to_s()
click to toggle source
returns the emoji
# File lib/emoji2020.rb, line 1913 def to_s() @s end
to_unicode()
click to toggle source
returns the Unicode value of the current emoji
# File lib/emoji2020.rb, line 1919 def to_unicode() "U+{%s}" % self.to_a.map {|x| x.to_s(16)}.join(' ') end