Sha256: 41ebe30d0d32c1ae3fa5e27c0ca92f481fcdc845478fdd5148e308e2364af4cf

Contents?: true

Size: 748 Bytes

Versions: 6

Compression:

Stored size: 748 Bytes

Contents

# encoding: utf-8

module Emojidex
  # Holds a master list of categories
  class Categories
    attr_accessor :categories

    def initialize(categories_json = nil)
      if categories_json
        load_categories(categories_json)
      else
        load_standard_categories
      end
    end

    def load_categories(json)
      raw = JSON.parse(json, symbolize_names: true)
      raw = raw[:categories]

      @categories ||= {}
      raw.each do |category_info|
        category = Emojidex::Category.new category_info
        @categories[category.code.to_sym] = category
      end
    end

    def load_standard_categories
      load_categories(IO.read(
          File.expand_path('../../../emoji/categories.json', __FILE__)))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
emojidex-0.0.14 lib/emojidex/categories.rb
emojidex-0.0.13 lib/emojidex/categories.rb
emojidex-0.0.12 lib/emojidex/categories.rb
emojidex-0.0.11 lib/emojidex/categories.rb
emojidex-0.0.10 lib/emojidex/categories.rb
emojidex-0.0.9 lib/emojidex/categories.rb