Class: Emojidex::Data::Collection

Inherits:
Object
  • Object
show all
Includes:
CollectionAssetInformation, CollectionCache, CollectionMojiData
Defined in:
lib/emojidex/data/collection.rb

Overview

listing and search of standard UTF emoji

Direct Known Subclasses

Extended, UTF, Service::Collection

Instance Attribute Summary collapse

Attributes included from CollectionMojiData

#moji_code_index, #moji_code_string

Attributes included from CollectionCache

#cache_path, #download_queue, #download_threads, #formats, #sizes

Instance Method Summary collapse

Methods included from CollectionMojiData

#condense_moji_code_data

Methods included from CollectionAssetInformation

#generate_checksums, #generate_paths, #get_checksums, #get_combo_checksums, #get_combo_paths, #get_paths, #get_paths?

Methods included from CollectionCache

#cache, #cache!, #cache_index, #load_cache, #setup_cache, #write_index

Constructor Details

#initialize(opts = {}) ⇒ Collection

Initialize Collection. You can pass a list of emoji to seed the collection



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/emojidex/data/collection.rb', line 23

def initialize(opts = {})
  @emoji = {}
  @raster_source_path = @vector_source_path = @source_path = nil
  @r18 = opts[:r18] || false
  if opts.include? :cache_path
    setup_cache(opts[:cache_path])
    opts.delete :cache_path
  else
    setup_cache
  end
  load_local_collection(opts[:local_load_path]) if opts.include? :local_load_path
  add_emoji(opts[:emoji]) if opts.include? :emoji
  @emoji
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



18
19
20
# File 'lib/emojidex/data/collection.rb', line 18

def categories
  @categories
end

#emojiObject

Returns the value of attribute emoji.



18
19
20
# File 'lib/emojidex/data/collection.rb', line 18

def emoji
  @emoji
end

#r18Object

Returns the value of attribute r18.



18
19
20
# File 'lib/emojidex/data/collection.rb', line 18

def r18
  @r18
end

#raster_source_pathObject

Returns the value of attribute raster_source_path.



18
19
20
# File 'lib/emojidex/data/collection.rb', line 18

def raster_source_path
  @raster_source_path
end

#source_pathObject

Returns the value of attribute source_path.



18
19
20
# File 'lib/emojidex/data/collection.rb', line 18

def source_path
  @source_path
end

#vector_source_pathObject

Returns the value of attribute vector_source_path.



18
19
20
# File 'lib/emojidex/data/collection.rb', line 18

def vector_source_path
  @vector_source_path
end

Instance Method Details

#add_emoji(list) ⇒ Object Also known as: <<

Adds emojis to the collection After add categories are updated



127
128
129
130
131
132
133
134
# File 'lib/emojidex/data/collection.rb', line 127

def add_emoji(list)
  _add_list(list)
  categorize
  associate_variants
  associate_customizations
  condense_moji_code_data
  @emoji
end

#category(category_code) ⇒ Object

Get all emoji from this collection that are part of the specified category Returns a new collection of only emoji in the specified category



114
115
116
117
# File 'lib/emojidex/data/collection.rb', line 114

def category(category_code)
  categorized = @emoji.values.select { |moji| moji.category == category_code }
  Emojidex::Data::Collection.new(emoji: categorized, r18: @r18)
end

#category?(*category_codes) ⇒ Boolean

Check to see if there are emoji in this collection which have the specified categories Returns true if there are emoji for all secified categories within this collection

Returns:

  • (Boolean)


121
122
123
# File 'lib/emojidex/data/collection.rb', line 121

def category?(*category_codes)
  (category_codes.uniq - @categories).empty?
end

#collect(&block) ⇒ Object



67
68
69
# File 'lib/emojidex/data/collection.rb', line 67

def collect(&block)
  @emoji.values.collect(&block)
end

#each(&block) ⇒ Object

each override to map each functionality to the emoji hash values



54
55
56
# File 'lib/emojidex/data/collection.rb', line 54

def each(&block)
  @emoji.values.each(&block)
end

#emojisObject



49
50
51
# File 'lib/emojidex/data/collection.rb', line 49

def emojis
  @emoji.values
end

#find_by_code(code) ⇒ Object

Gets the emoji with the specified code Returns the Emoji object or nil if no emoji with that code is found



84
85
86
# File 'lib/emojidex/data/collection.rb', line 84

def find_by_code(code)
  @emoji[code.gsub(/\s/, '_').to_sym]
end

#find_by_code_ja(code_ja) ⇒ Object Also known as: コード検索

Locates emoji by Japanese code (original Japanese emoji name [絵文字名]) Only applies to collections that contain JA codes, this function is mapped to find_by_code for all other implementations (such as client)



91
92
93
94
95
96
# File 'lib/emojidex/data/collection.rb', line 91

def find_by_code_ja(code_ja)
  each do |m|
    return m if m[:code_ja] == code_ja
  end
  nil
end

#find_by_moji(moji) ⇒ Object Also known as: 文字検索

Retreives an Emoji object by the actual moji code/character code Will likely only return moji from UTF collection



73
74
75
76
77
78
# File 'lib/emojidex/data/collection.rb', line 73

def find_by_moji(moji)
  each do |m|
    return m if m[:moji] == moji
  end
  nil
end

#find_by_unicode(unicode) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/emojidex/data/collection.rb', line 100

def find_by_unicode(unicode)
  unicode = unicode.downcase
  each do |m|
    return m if m[:unicode] == unicode
  end
  nil
end

#load_local_collection(path) ⇒ Object

Loads an emoji collection on local storage



39
40
41
42
43
44
45
46
47
# File 'lib/emojidex/data/collection.rb', line 39

def load_local_collection(path)
  @source_path = File.expand_path(path)
  @vector_source_path = @source_path if @vector_source_path.nil?
  @raster_source_path = @source_path if @raster_source_path.nil?
  json = IO.read(@source_path + '/emoji.json')
  list = JSON.parse(json, symbolize_names: true)
  add_emoji(list)
  generate_paths
end

#map(&block) ⇒ Object



63
64
65
# File 'lib/emojidex/data/collection.rb', line 63

def map(&block)
  @emoji.values.map(&block)
end

#remove_emoji(code) ⇒ Object



138
139
140
141
# File 'lib/emojidex/data/collection.rb', line 138

def remove_emoji(code)
  emoji.delete(code)
  @emoji
end

#search(criteria = {}) ⇒ Object



108
109
110
# File 'lib/emojidex/data/collection.rb', line 108

def search(criteria = {})
  Emojidex::Data::Collection.new(emoji: _sub_search(@emoji.values.dup, criteria))
end

#select(&block) ⇒ Object

select override to map select functionality to the emoji hash values



59
60
61
# File 'lib/emojidex/data/collection.rb', line 59

def select(&block)
  @emoji.values.select(&block)
end