Class: Gemojione::Index
- Inherits:
-
Object
- Object
- Gemojione::Index
- Defined in:
- lib/gemojione/index.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
Instance Method Summary collapse
- #ascii_moji_regex ⇒ Object
- #find_by_ascii(ascii) ⇒ Object
- #find_by_category(category) ⇒ Object
- #find_by_keyword(keyword) ⇒ Object
- #find_by_moji(moji) ⇒ Object
- #find_by_name(name) ⇒ Object
- #find_by_shortname(shortname) ⇒ Object
- #find_by_unicode(unicode) ⇒ Object
-
#initialize(emoji_list = nil) ⇒ Index
constructor
A new instance of Index.
- #shortname_moji_regex ⇒ Object
- #unicode_moji_regex ⇒ Object
Constructor Details
#initialize(emoji_list = nil) ⇒ Index
Returns a new instance of Index.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gemojione/index.rb', line 5 def initialize(emoji_list=nil) emoji_list ||= begin emoji_json = File.read(File.absolute_path(File.dirname(__FILE__) + '/../../config/index.json')) JSON.parse(emoji_json) end @emoji_by_name = {} @emoji_by_moji = {} @emoji_by_ascii = {} @emoji_by_code = {} @emoji_by_keyword = {} @emoji_by_category = {} @emoji_by_unicode = {} @all = emoji_list emoji_list.each do |key, emoji_hash| emoji_hash["description"] = emoji_hash["name"] emoji_hash["name"] = key @emoji_by_name[key] = emoji_hash if key emoji_hash["aliases"].each do |emoji_alias| aliased = emoji_alias.tr(':','') @emoji_by_name[aliased] = emoji_hash if aliased @emoji_by_code[emoji_alias] = emoji_hash if aliased end emoji_hash['aliases_ascii'].each do |emoji_ascii| @emoji_by_ascii[emoji_ascii] = emoji_hash if emoji_ascii end code = emoji_hash['shortname'] @emoji_by_code[code] = emoji_hash if code moji = emoji_hash['moji'] @emoji_by_moji[moji] = emoji_hash if moji unicode = emoji_hash['unicode'] @emoji_by_unicode[unicode] = emoji_hash if unicode emoji_hash['keywords'].each do |emoji_keyword| @emoji_by_keyword[emoji_keyword] ||= [] @emoji_by_keyword[emoji_keyword] << emoji_hash end category = emoji_hash['category'] if category @emoji_by_category[category] ||= {} @emoji_by_category[category][key] = emoji_hash end end @emoji_code_regex = /#{@emoji_by_code.keys.map{|ec| Regexp.escape(ec)}.join('|')}/ @emoji_moji_regex = /#{@emoji_by_moji.keys.sort { |a, b| b.length <=> a.length }.map{|ec| Regexp.escape(ec)}.join('|')}/ @emoji_ascii_regex = /#{@emoji_by_ascii.keys.map{|ec| Regexp.escape(ec)}.join('|')}/ end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
3 4 5 |
# File 'lib/gemojione/index.rb', line 3 def all @all end |
Instance Method Details
#ascii_moji_regex ⇒ Object
98 99 100 |
# File 'lib/gemojione/index.rb', line 98 def ascii_moji_regex @emoji_ascii_regex end |
#find_by_ascii(ascii) ⇒ Object
70 71 72 |
# File 'lib/gemojione/index.rb', line 70 def find_by_ascii(ascii) @emoji_by_ascii[ascii] end |
#find_by_category(category) ⇒ Object
78 79 80 |
# File 'lib/gemojione/index.rb', line 78 def find_by_category(category) @emoji_by_category[category] end |
#find_by_keyword(keyword) ⇒ Object
74 75 76 |
# File 'lib/gemojione/index.rb', line 74 def find_by_keyword(keyword) @emoji_by_keyword[keyword] end |
#find_by_moji(moji) ⇒ Object
62 63 64 |
# File 'lib/gemojione/index.rb', line 62 def find_by_moji(moji) @emoji_by_moji[moji] end |
#find_by_name(name) ⇒ Object
66 67 68 |
# File 'lib/gemojione/index.rb', line 66 def find_by_name(name) @emoji_by_name[name] end |
#find_by_shortname(shortname) ⇒ Object
82 83 84 |
# File 'lib/gemojione/index.rb', line 82 def find_by_shortname(shortname) @emoji_by_code[shortname] end |
#find_by_unicode(unicode) ⇒ Object
86 87 88 |
# File 'lib/gemojione/index.rb', line 86 def find_by_unicode(unicode) @emoji_by_unicode[unicode] end |
#shortname_moji_regex ⇒ Object
94 95 96 |
# File 'lib/gemojione/index.rb', line 94 def shortname_moji_regex @emoji_code_regex end |
#unicode_moji_regex ⇒ Object
90 91 92 |
# File 'lib/gemojione/index.rb', line 90 def unicode_moji_regex @emoji_moji_regex end |