Class: Emoju::Data
- Inherits:
-
Object
- Object
- Emoju::Data
- Defined in:
- lib/emoju/data.rb
Constant Summary collapse
- GEM_ROOT =
File.join(File.dirname(__FILE__), "../..")
- VENDOR_DATA =
"data/emoji.json"
Instance Attribute Summary collapse
-
#emoji_docomo_map ⇒ Object
readonly
Returns the value of attribute emoji_docomo_map.
-
#emoji_google_map ⇒ Object
readonly
Returns the value of attribute emoji_google_map.
-
#emoji_softbank_map ⇒ Object
readonly
Returns the value of attribute emoji_softbank_map.
Instance Method Summary collapse
- #codepoint_regexp(codepoints) ⇒ Object
- #emoji_docomo_regexp ⇒ Object
- #emoji_google_regexp ⇒ Object
- #emoji_softbank_regexp ⇒ Object
-
#initialize ⇒ Data
constructor
A new instance of Data.
- #regexp_for(encoding) ⇒ Object
Constructor Details
#initialize ⇒ Data
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/emoju/data.rb', line 10 def initialize @emoji_docomo_map = {} @emoji_softbank_map = {} @emoji_google_map = {} raw_json = IO.read(File.join(GEM_ROOT, VENDOR_DATA)) vendordata = JSON.parse( raw_json ) vendordata.each do |emoji| @emoji_softbank_map[emoji["softbank"]] = emoji["unified"] if emoji["softbank"] @emoji_docomo_map[emoji["docomo"]] = emoji["unified"] if emoji["docomo"] @emoji_google_map[emoji["google"]] = emoji["unified"] if emoji["google"] end end |
Instance Attribute Details
#emoji_docomo_map ⇒ Object (readonly)
Returns the value of attribute emoji_docomo_map.
8 9 10 |
# File 'lib/emoju/data.rb', line 8 def emoji_docomo_map @emoji_docomo_map end |
#emoji_google_map ⇒ Object (readonly)
Returns the value of attribute emoji_google_map.
8 9 10 |
# File 'lib/emoju/data.rb', line 8 def emoji_google_map @emoji_google_map end |
#emoji_softbank_map ⇒ Object (readonly)
Returns the value of attribute emoji_softbank_map.
8 9 10 |
# File 'lib/emoju/data.rb', line 8 def emoji_softbank_map @emoji_softbank_map end |
Instance Method Details
#codepoint_regexp(codepoints) ⇒ Object
46 47 48 |
# File 'lib/emoju/data.rb', line 46 def codepoint_regexp(codepoints) codepoints.split("-").map { |codepoint| "\\u\{#{codepoint}\}" }.join end |
#emoji_docomo_regexp ⇒ Object
34 35 36 |
# File 'lib/emoju/data.rb', line 34 def emoji_docomo_regexp regexp_for(:google) end |
#emoji_google_regexp ⇒ Object
30 31 32 |
# File 'lib/emoju/data.rb', line 30 def emoji_google_regexp regexp_for(:docomo) end |
#emoji_softbank_regexp ⇒ Object
26 27 28 |
# File 'lib/emoju/data.rb', line 26 def emoji_softbank_regexp regexp_for(:softbank) end |
#regexp_for(encoding) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/emoju/data.rb', line 38 def regexp_for(encoding) regexp = instance_variable_get("@emoji_#{encoding}_map".to_sym).keys. map { |codepoints| codepoint_regexp(codepoints) }. join("|") Regexp.new(regexp).freeze end |