Class: Somemoji::Emoji

Inherits:
Object
  • Object
show all
Defined in:
lib/somemoji/emoji.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aliases: nil, ascii_arts: nil, category: nil, code:, code_points: nil, code_points_alternates: nil, keywords: nil, name: nil) ⇒ Emoji

Returns a new instance of Emoji

Examples:

emoji = Somemoji::Emoji.new(
  aliases: [],
  ascii_arts: [],
  category: "symbols",
  code: "100",
  code_points: [
    "1F4AF"
  ],
  code_points_alternates: [],
  keywords: [
    "100",
    "a",
    "exam",
    "numbers",
    "parties",
    "percent",
    "perfect",
    "plus",
    "quiz",
    "school",
    "score",
    "symbol",
    "test",
    "win",
    "wow"
  ],
  name: "hundred points symbol"
)
emoji.character #=> "💯"

Parameters:

  • aliases (Array<String>, nil)
  • ascii_arts (Array<String>, nil)
  • category (String, nil)
  • code_points_alternates (Array<Array<String>>, nil)
  • code_points (Array<String>, nil)
  • code (String)

    a unique emoji code (required)

  • keywords (Array<String>, nil)
  • name (String, nil)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/somemoji/emoji.rb', line 65

def initialize(
  aliases: nil,
  ascii_arts: nil,
  category: nil,
  code:,
  code_points: nil,
  code_points_alternates: nil,
  keywords: nil,
  name: nil
)
  @aliases = aliases || []
  @ascii_arts = ascii_arts || []
  @category = category
  @code = code
  @code_points = code_points || []
  @code_points_alternates = code_points_alternates || []
  @keywords = keywords || []
  @name = name
end

Instance Attribute Details

#aliasesArray<String> (readonly)

Returns:

  • (Array<String>)


4
5
6
# File 'lib/somemoji/emoji.rb', line 4

def aliases
  @aliases
end

#ascii_artsArray<String> (readonly)

Returns:

  • (Array<String>)


7
8
9
# File 'lib/somemoji/emoji.rb', line 7

def ascii_arts
  @ascii_arts
end

#categoryString? (readonly)

Returns:

  • (String, nil)


10
11
12
# File 'lib/somemoji/emoji.rb', line 10

def category
  @category
end

#codeString? (readonly)

Returns:

  • (String, nil)


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

def code
  @code
end

#code_pointsArray<String>? (readonly)

Returns:

  • (Array<String>, nil)


16
17
18
# File 'lib/somemoji/emoji.rb', line 16

def code_points
  @code_points
end

#code_points_alternatesArray<Array<String>> (readonly)

Returns:

  • (Array<Array<String>>)


19
20
21
# File 'lib/somemoji/emoji.rb', line 19

def code_points_alternates
  @code_points_alternates
end

#keywordsArray<String>? (readonly)

Returns:

  • (Array<String>, nil)


22
23
24
# File 'lib/somemoji/emoji.rb', line 22

def keywords
  @keywords
end

#nameString? (readonly)

Returns:

  • (String, nil)


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

def name
  @name
end

Instance Method Details

#alternate_charactersArray<String>

Returns:

  • (Array<String>)


86
87
88
89
90
91
92
# File 'lib/somemoji/emoji.rb', line 86

def alternate_characters
  code_points_alternates.map do |code_points_alternate|
    code_points_alternate.map do |code_point|
      code_point.to_i(16)
    end.pack("U*")
  end
end

#base_pathString

Returns:

  • (String)


95
96
97
98
99
100
101
# File 'lib/somemoji/emoji.rb', line 95

def base_path
  if code_points.empty?
    code
  else
    "unicode/#{code_points.join('-').downcase}"
  end
end

#characterString?

Returns a String representation from its code points

Returns:

  • (String, nil)

    a String representation from its code points



104
105
106
107
108
109
110
# File 'lib/somemoji/emoji.rb', line 104

def character
  unless code_points.empty?
    code_points.map do |code_point|
      code_point.to_i(16)
    end.pack("U*")
  end
end