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.
-
#r18 ⇒ Object
Returns the value of attribute r18.
-
#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.
- #emojis ⇒ Object
-
#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!, #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
#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 |
#r18 ⇒ Object
Returns the value of attribute r18.
18 19 20 |
# File 'lib/emojidex/data/collection.rb', line 18 def r18 @r18 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
125 126 127 128 129 130 131 |
# File 'lib/emojidex/data/collection.rb', line 125 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
112 113 114 115 |
# File 'lib/emojidex/data/collection.rb', line 112 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
119 120 121 |
# File 'lib/emojidex/data/collection.rb', line 119 def category?(*category_codes) (category_codes.uniq - @categories).empty? end |
#collect(&block) ⇒ Object
65 66 67 |
# File 'lib/emojidex/data/collection.rb', line 65 def collect(&block) @emoji.values.collect(&block) end |
#each(&block) ⇒ Object
each override to map each functionality to the emoji hash values
52 53 54 |
# File 'lib/emojidex/data/collection.rb', line 52 def each(&block) @emoji.values.each(&block) end |
#emojis ⇒ Object
47 48 49 |
# File 'lib/emojidex/data/collection.rb', line 47 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
82 83 84 |
# File 'lib/emojidex/data/collection.rb', line 82 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)
89 90 91 92 93 94 |
# File 'lib/emojidex/data/collection.rb', line 89 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
71 72 73 74 75 76 |
# File 'lib/emojidex/data/collection.rb', line 71 def find_by_moji(moji) each do |m| return m if m[:moji] == moji end nil end |
#find_by_unicode(unicode) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/emojidex/data/collection.rb', line 98 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 |
# File 'lib/emojidex/data/collection.rb', line 39 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
61 62 63 |
# File 'lib/emojidex/data/collection.rb', line 61 def map(&block) @emoji.values.map(&block) end |
#remove_emoji(code) ⇒ Object
135 136 137 138 |
# File 'lib/emojidex/data/collection.rb', line 135 def remove_emoji(code) emoji.delete(code) @emoji end |
#search(criteria = {}) ⇒ Object
106 107 108 |
# File 'lib/emojidex/data/collection.rb', line 106 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
57 58 59 |
# File 'lib/emojidex/data/collection.rb', line 57 def select(&block) @emoji.values.select(&block) end |