Class: VaderSentimentRuby::EmojiDescriber

Inherits:
Object
  • Object
show all
Defined in:
lib/vader_sentiment_ruby/emojis_describer.rb

Overview

Replaces emoji characters with their descriptions

Instance Method Summary collapse

Constructor Details

#initialize(text, emoji_dictionary) ⇒ EmojiDescriber

Returns a new instance of EmojiDescriber.

Parameters:

  • text (String)

    Original text

  • emoji_dictionary (Hash)

    Emoji dictionary with emojis as keys



8
9
10
11
12
13
# File 'lib/vader_sentiment_ruby/emojis_describer.rb', line 8

def initialize(text, emoji_dictionary)
  @text_array = text.split('')
  @emoji_dictionary = emoji_dictionary
  @text_no_emoji = ''
  @prev_space = true
end

Instance Method Details

#callString

Returns Text with emojis replaced with descriptions.

Returns:

  • (String)

    Text with emojis replaced with descriptions



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vader_sentiment_ruby/emojis_describer.rb', line 16

def call
  @text_array.each do |character|
    if @emoji_dictionary.keys.include?(character)
      replace_emoji_with_description(character)
    else
      handle_simple_character(character)
    end
  end

  @text_no_emoji
end