Sha256: c7e21d5f29fd748711990273fb3b41d95fc880a5ec9c670b45d30653d4792667

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

class EmojiData
  PATH = File.expand_path("../UTR_51/emoji-data.txt".freeze, "lib/emoji/data".freeze)

  def initialize
    @raw_lines = IO.readlines(PATH)
    @emoji_lines = @raw_lines[20..158].map(&:chomp)
    @emoji_presentation_lines = @raw_lines[167..233].map(&:chomp)
    @emoji_modifier_line = @raw_lines[242].chomp
    @emoji_modifier_base_lines = @raw_lines[251..274].map(&:chomp)
  end

  def emojis
    @_emojis ||= emoji_lines.map do |line|
      DataBase.new(line)
    end
  end

  def emoji_presentations
    @_emoji_presentations ||= emoji_presentation_lines.map do |line|
      DataBase.new(line)
    end
  end

  def emoji_modifiers
    @_emoji_modifiers ||= Array(DataBase.new(emoji_modifier_line))
  end

  def emoji_modifier_bases
    @_emoji_modifier_bases ||= emoji_modifier_base_lines.map do |line|
      DataBase.new(line)
    end
  end

  def all
    [emojis, emoji_presentations, emoji_modifiers, emoji_modifier_bases].flatten(1)
  end

  private

    attr_reader :emoji_lines, :emoji_presentation_lines
    attr_reader :emoji_modifier_line, :emoji_modifier_base_lines
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
emoji-data-1.0.0 lib/emoji/data/emoji_data.rb
emoji-data-0.1.0 lib/emoji/data/emoji_data.rb