Sha256: 0c758dff36541dd52e487f2fd214f32f2d1373d12102e5899885480fefe1cb55

Contents?: true

Size: 1.77 KB

Versions: 8

Compression:

Stored size: 1.77 KB

Contents

require_relative '../../emojidex'
require_relative 'emoji/asset_information'

module Emojidex
  module Data
    # emoji base class
    class Emoji
      attr_accessor :moji, :category, :code, :code_ja,
                    :unicode, :tags, :emoticon, :variants, :base,
                    :r18

      include Emojidex::Data::EmojiAssetInformation

      def initialize(details = {})
        _init_identifier_info(details)
        _init_descriptor_info(details)
        init_asset_info(details)
      end

      def to_s
        @moji || Emojidex.encapsulate_code(@code)
      end

      def to_json(*args)
        to_hash.to_json(*args)
      end

      def to_hash
        hash = {}
        instance_variables.each do |key|
          hash[key.to_s.delete('@')] = instance_variable_get(key)
        end
        hash
      end

      def [](key)
        instance_variable_get(key.to_s.delete(':').insert(0, '@'))
      end

      def []=(key, val)
        instance_variable_set(key.to_s.delete(':').insert(0, '@'), val)
      end

      private

      def _init_identifier_info(details)
        @moji = details[:moji].to_s
        @code = Emojidex.escape_code(details[:code].to_s)
        @code_ja = Emojidex.escape_code(details[:code_ja].to_s)
        @unicode = details[:unicode].to_s
        @full_name = details[:full_name].to_s
        @emoticon = details[:emoticon].to_s
        @r18 = details[:r18] || false
      end

      def _init_descriptor_info(details)
        @category = details[:category] ? details[:category].to_sym : :other
        @tags = details[:tags].map(&:to_sym) unless details[:tags].nil?
        @link = details[:link].to_s
        @variants = details[:variants] || []
        @variants.uniq!
        @base = details[:base]
        @is_wide = details[:is_wide]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
emojidex-0.3.5 lib/emojidex/data/emoji.rb
emojidex-0.3.4 lib/emojidex/data/emoji.rb
emojidex-0.3.3 lib/emojidex/data/emoji.rb
emojidex-0.3.2 lib/emojidex/data/emoji.rb
emojidex-0.3.1 lib/emojidex/data/emoji.rb
emojidex-0.3.0 lib/emojidex/data/emoji.rb
emojidex-0.2.3 lib/emojidex/data/emoji.rb
emojidex-0.2.2 lib/emojidex/data/emoji.rb