Class: Rumoji::Emoji

Inherits:
Object
  • Object
show all
Defined in:
lib/rumoji/emoji.rb,
lib/rumoji/emoji/nature.rb,
lib/rumoji/emoji/people.rb,
lib/rumoji/emoji/places.rb,
lib/rumoji/emoji/objects.rb,
lib/rumoji/emoji/symbols.rb

Constant Summary collapse

ALL =
PEOPLE | NATURE | OBJECTS | PLACES | SYMBOLS
NATURE =
Set[
self.new("\u{2600}" , [:sunny]
PEOPLE =
Set[
self.new("\u{1F604}", [:smile]
PLACES =
Set[
self.new("\u{1f6a1}", [:aerial_tramway]
OBJECTS =
Set[
self.new("\u{1F38D}", [:bamboo]
SYMBOLS =
Set[
self.new("\u{1f4af}", [:"100"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, symbols, name = nil) ⇒ Emoji

Returns a new instance of Emoji.



7
8
9
10
11
# File 'lib/rumoji/emoji.rb', line 7

def initialize(string, symbols, name = nil)
  @codepoints = string.codepoints
  @cheat_codes = [symbols].flatten
  @name = name || @cheat_codes.first.to_s.upcase.gsub("_", " ")
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rumoji/emoji.rb', line 5

def name
  @name
end

Class Method Details

.find(symbol) ⇒ Object



45
46
47
# File 'lib/rumoji/emoji.rb', line 45

def self.find(symbol)
  ALL.find {|emoji| emoji.include? symbol }
end

.find_by_codepoint(codepoint) ⇒ Object



53
54
55
# File 'lib/rumoji/emoji.rb', line 53

def self.find_by_codepoint(codepoint)
  ALL.find {|emoji| emoji.hex == codepoint.to_s(16).upcase }
end

.find_by_string(string) ⇒ Object



49
50
51
# File 'lib/rumoji/emoji.rb', line 49

def self.find_by_string(string)
  ALL.find {|emoji| emoji.to_s == string }
end

Instance Method Details

#codeObject



17
18
19
# File 'lib/rumoji/emoji.rb', line 17

def code
  ":#{symbol}:"
end

#hashObject



29
30
31
# File 'lib/rumoji/emoji.rb', line 29

def hash
  code.hash
end

#hexObject



33
34
35
# File 'lib/rumoji/emoji.rb', line 33

def hex
  @codepoints.map{|point| point.to_s(16).upcase }.join("-")
end

#include?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rumoji/emoji.rb', line 21

def include?(symbol)
  @cheat_codes.include? symbol.to_sym
end

#symbolObject



13
14
15
# File 'lib/rumoji/emoji.rb', line 13

def symbol
  @cheat_codes.first
end

#to_sObject



25
26
27
# File 'lib/rumoji/emoji.rb', line 25

def to_s
  @codepoints.to_a.pack("U*")
end