Class: Emojidex::Data::Collection
- Inherits:
-
Object
- Object
- Emojidex::Data::Collection
- Defined in:
- lib/emojidex/data/collection.rb
Overview
listing and search of standard UTF emoji
Direct Known Subclasses
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#emoji ⇒ Object
Returns the value of attribute emoji.
-
#raster_source_path ⇒ Object
Returns the value of attribute raster_source_path.
-
#source_path ⇒ Object
Returns the value of attribute source_path.
-
#vector_source_path ⇒ Object
Returns the value of attribute vector_source_path.
Attributes included from CollectionMojiData
#moji_code_index, #moji_code_string
Attributes included from CollectionCache
#cache_path, #download_queue, #download_threads
Instance Method Summary collapse
-
#add_emoji(list) ⇒ Object
(also: #<<)
Adds emojis to the collection After add categories are updated.
-
#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.
-
#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.
- #collect(&block) ⇒ Object
-
#each(&block) ⇒ Object
each override to map each functionality to the emoji hash values.
-
#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.
-
#find_by_code_ja(code_ja) ⇒ Object
(also: #コード検索)
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).
-
#find_by_moji(moji) ⇒ Object
(also: #文字検索)
Retreives an Emoji object by the actual moji code/character code Will likely only return moji from UTF collection.
- #find_by_unicode(unicode) ⇒ Object
-
#initialize(opts = {}) ⇒ Collection
constructor
Initialize Collection.
-
#load_local_collection(path) ⇒ Object
Loads an emoji collection on local storage.
- #map(&block) ⇒ Object
- #remove_emoji(code) ⇒ Object
- #search(criteria = {}) ⇒ Object
-
#select(&block) ⇒ Object
select override to map select functionality to the emoji hash values.
Methods included from CollectionMojiData
Methods included from CollectionAssetInformation
#generate_checksums, #generate_paths, #get_checksums, #get_paths, #get_paths?
Methods included from CollectionCache
#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
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/emojidex/data/collection.rb', line 22 def initialize(opts = {}) @emoji = {} @raster_source_path = @vector_source_path = @source_path = nil 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
#categories ⇒ Object
Returns the value of attribute categories.
18 19 20 |
# File 'lib/emojidex/data/collection.rb', line 18 def categories @categories end |
#emoji ⇒ Object
Returns the value of attribute emoji.
18 19 20 |
# File 'lib/emojidex/data/collection.rb', line 18 def emoji @emoji end |
#raster_source_path ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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
119 120 121 122 123 124 125 |
# File 'lib/emojidex/data/collection.rb', line 119 def add_emoji(list) _add_list(list) categorize associate_variants 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
106 107 108 109 |
# File 'lib/emojidex/data/collection.rb', line 106 def category(category_code) categorized = @emoji.values.select { |moji| moji.category == category_code } Emojidex::Data::Collection.new(emoji: categorized) 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
113 114 115 |
# File 'lib/emojidex/data/collection.rb', line 113 def category?(*category_codes) (category_codes.uniq - @categories).empty? end |
#collect(&block) ⇒ Object
59 60 61 |
# File 'lib/emojidex/data/collection.rb', line 59 def collect(&block) @emoji.values.collect(&block) end |
#each(&block) ⇒ Object
each override to map each functionality to the emoji hash values
46 47 48 |
# File 'lib/emojidex/data/collection.rb', line 46 def each(&block) @emoji.values.each(&block) 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
76 77 78 |
# File 'lib/emojidex/data/collection.rb', line 76 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)
83 84 85 86 87 88 |
# File 'lib/emojidex/data/collection.rb', line 83 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
65 66 67 68 69 70 |
# File 'lib/emojidex/data/collection.rb', line 65 def find_by_moji(moji) each do |m| return m if m[:moji] == moji end nil end |
#find_by_unicode(unicode) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/emojidex/data/collection.rb', line 92 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
37 38 39 40 41 42 43 |
# File 'lib/emojidex/data/collection.rb', line 37 def load_local_collection(path) @source_path = @vector_source_path = @raster_source_path = File.(path) json = IO.read(@source_path + '/emoji.json') list = JSON.parse(json, symbolize_names: true) add_emoji(list) generate_paths end |
#map(&block) ⇒ Object
55 56 57 |
# File 'lib/emojidex/data/collection.rb', line 55 def map(&block) @emoji.values.map(&block) end |
#remove_emoji(code) ⇒ Object
129 130 131 132 |
# File 'lib/emojidex/data/collection.rb', line 129 def remove_emoji(code) emoji.delete(code) @emoji end |
#search(criteria = {}) ⇒ Object
100 101 102 |
# File 'lib/emojidex/data/collection.rb', line 100 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
51 52 53 |
# File 'lib/emojidex/data/collection.rb', line 51 def select(&block) @emoji.values.select(&block) end |