Module: EmojiData
- Defined in:
- lib/emoji_data.rb,
lib/emoji_data/version.rb,
lib/emoji_data/emoji_char.rb
Defined Under Namespace
Classes: EmojiChar
Constant Summary collapse
- VERSION =
Current version of the module, for bundling to rubygems.org
"0.2.0"
Class Method Summary collapse
-
.all ⇒ Array<EmojiChar>
Returns a list of all known Emoji characters as
EmojiChar
objects. -
.all_doublebyte ⇒ Array<EmojiChar>
Returns a list of all
EmojiChar
that are represented with doublebyte encoding. -
.all_with_variants ⇒ Array<EmojiChar>
Returns a list of all
EmojiChar
that have at least one variant encoding. -
.char_to_unified(char) ⇒ String
Convert a native UTF-8 string glyph to its unified codepoint ID.
-
.chars(opts = {}) ⇒ Array<String>
Returns a list of all known Emoji characters rendered as UTF-8 strings.
-
.codepoints(opts = {}) ⇒ Array<String>
Returns a list of all known codepoints representing Emoji characters.
-
.find_by_name(name) ⇒ Array<EmojiChar>
Finds any
EmojiChar
that contains given string in its official name. -
.find_by_short_name(short_name) ⇒ Array<EmojiChar>
Find all
EmojiChar
that match string in any of their associated short name keywords. -
.from_short_name(short_name) ⇒ EmojiChar
Finds a specific
EmojiChar
based on the unified codepoint ID. -
.from_unified(uid) ⇒ EmojiChar
(also: find_by_unified)
Finds a specific
EmojiChar
based on its unified codepoint ID. -
.scan(str) ⇒ Array<EmojiChar>
(also: find_by_str)
Scans a string for all encoded emoji characters contained within.
-
.unified_to_char(uid) ⇒ String
Convert a unified codepoint ID directly to its UTF-8 string representation.
Class Method Details
.all ⇒ Array<EmojiChar>
Returns a list of all known Emoji characters as EmojiChar
objects.
39 40 41 |
# File 'lib/emoji_data.rb', line 39 def self.all EMOJI_CHARS end |
.all_doublebyte ⇒ Array<EmojiChar>
Returns a list of all EmojiChar
that are represented with doublebyte
encoding.
47 48 49 |
# File 'lib/emoji_data.rb', line 47 def self.all_doublebyte EMOJI_CHARS.select(&:doublebyte?) end |
.all_with_variants ⇒ Array<EmojiChar>
Returns a list of all EmojiChar
that have at least one variant encoding.
54 55 56 |
# File 'lib/emoji_data.rb', line 54 def self.all_with_variants EMOJI_CHARS.select(&:variant?) end |
.char_to_unified(char) ⇒ String
Convert a native UTF-8 string glyph to its unified codepoint ID.
This is a conversion operation, not a match, so it may produce unexpected results with different types of values.
110 111 112 |
# File 'lib/emoji_data.rb', line 110 def self.char_to_unified(char) char.codepoints.to_a.map { |i| i.to_s(16).rjust(4,'0')}.join('-').upcase end |
.chars(opts = {}) ⇒ Array<String>
Returns a list of all known Emoji characters rendered as UTF-8 strings.
By default, the default rendering options for this library will be used.
However, if you pass an option hash with include_variants: true
then all
possible renderings of a single glyph will be included, meaning that:
- You will have "duplicate" emojis in your list.
- This list is now suitable for exhaustably matching against in a search.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/emoji_data.rb', line 71 def self.chars(opts={}) = {include_variants: false}.merge(opts) normals = EMOJI_CHARS.map { |c| c.render({variant_encoding: false}) } if [:include_variants] extras = self.all_with_variants.map { |c| c.render({variant_encoding: true}) } return normals + extras end normals end |
.codepoints(opts = {}) ⇒ Array<String>
Returns a list of all known codepoints representing Emoji characters.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/emoji_data.rb', line 87 def self.codepoints(opts={}) = {include_variants: false}.merge(opts) normals = EMOJI_CHARS.map(&:unified) if [:include_variants] extras = self.all_with_variants.map {|c| c.variant} return normals + extras end normals end |
.find_by_name(name) ⇒ Array<EmojiChar>
Finds any EmojiChar
that contains given string in its official name.
160 161 162 |
# File 'lib/emoji_data.rb', line 160 def self.find_by_name(name) self.find_by_value(:name, name.upcase) end |
.find_by_short_name(short_name) ⇒ Array<EmojiChar>
Find all EmojiChar
that match string in any of their associated short
name keywords.
169 170 171 |
# File 'lib/emoji_data.rb', line 169 def self.find_by_short_name(short_name) self.find_by_value(:short_name, short_name.downcase) end |
.from_short_name(short_name) ⇒ EmojiChar
Finds a specific EmojiChar
based on the unified codepoint ID.
Must be exact match.
179 180 181 |
# File 'lib/emoji_data.rb', line 179 def self.from_short_name(short_name) EMOJICHAR_KEYWORD_MAP[short_name.downcase] end |
.from_unified(uid) ⇒ EmojiChar Also known as: find_by_unified
Finds a specific EmojiChar
based on its unified codepoint ID.
130 131 132 |
# File 'lib/emoji_data.rb', line 130 def self.from_unified(uid) EMOJICHAR_UNIFIED_MAP[uid.upcase] end |
.scan(str) ⇒ Array<EmojiChar> Also known as: find_by_str
Scans a string for all encoded emoji characters contained within.
151 152 153 154 |
# File 'lib/emoji_data.rb', line 151 def self.scan(str) matches = str.scan(FBS_REGEXP) matches.map { |m| EmojiData.from_unified(EmojiData.char_to_unified(m)) } end |
.unified_to_char(uid) ⇒ String
Convert a unified codepoint ID directly to its UTF-8 string representation.
122 123 124 |
# File 'lib/emoji_data.rb', line 122 def self.unified_to_char(uid) EmojiChar::unified_to_char(uid) end |