Class: Emoji::Extractor
- Inherits:
-
Object
- Object
- Emoji::Extractor
- Defined in:
- lib/emoji/extractor.rb
Defined Under Namespace
Classes: GlyphIndex
Constant Summary collapse
- EMOJI_TTF =
"/System/Library/Fonts/Apple Color Emoji.ttc"
Instance Attribute Summary collapse
-
#images_path ⇒ Object
readonly
Returns the value of attribute images_path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #extract! ⇒ Object
-
#initialize(size, images_path) ⇒ Extractor
constructor
A new instance of Extractor.
Constructor Details
#initialize(size, images_path) ⇒ Extractor
Returns a new instance of Extractor.
10 11 12 13 |
# File 'lib/emoji/extractor.rb', line 10 def initialize(size, images_path) @size = size @images_path = images_path end |
Instance Attribute Details
#images_path ⇒ Object (readonly)
Returns the value of attribute images_path.
8 9 10 |
# File 'lib/emoji/extractor.rb', line 8 def images_path @images_path end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/emoji/extractor.rb', line 8 def size @size end |
Instance Method Details
#each(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/emoji/extractor.rb', line 15 def each(&block) return to_enum(__method__) unless block_given? File.open(EMOJI_TTF, 'rb') do |file| font_offsets = parse_ttc(file) file.pos = font_offsets[0] tables = parse_tables(file) glyph_index = extract_glyph_index(file, tables) each_glyph_bitmap(file, tables, glyph_index, &block) end end |
#extract! ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/emoji/extractor.rb', line 29 def extract! each do |glyph_name, type, binread| if emoji = glyph_name_to_emoji(glyph_name) image_filename = "#{images_path}/#{emoji.image_filename}" FileUtils.mkdir_p(File.dirname(image_filename)) File.open(image_filename, 'wb') { |f| f.write binread.call } end end end |