Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rsyntaxtree/utils.rb

Instance Method Summary collapse

Instance Method Details

#all_emoji?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rsyntaxtree/utils.rb', line 21

def all_emoji?
  !!(gsub(WHITESPACE_BLOCK, "").gsub(/\d/, "") =~ /\A\p{Emoji}[\p{Emoji}\s]*\z/)
end

#contains_cjk?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rsyntaxtree/utils.rb', line 13

def contains_cjk?
  !!(gsub(WHITESPACE_BLOCK, "") =~ /\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}|[^\x01-\x7E]/)
end

#contains_emoji?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rsyntaxtree/utils.rb', line 17

def contains_emoji?
  !!(gsub(WHITESPACE_BLOCK, "").gsub(/\d/, "") =~ /\p{Emoji}/)
end

#split_by_emojiObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rsyntaxtree/utils.rb', line 25

def split_by_emoji
  results = []
  split(//).each do |ch|
    results << case ch
               when /\d/, WHITESPACE_BLOCK
                 { type: :normal, char: ch }
               when /\p{Emoji}/
                 { type: :emoji, char: ch }
               else
                 { type: :normal, char: ch }
               end
  end
  results.reject { |string| string == "" }
end