#!/usr/bin/env ruby
require 'json'

#maketxt.rb myemoj.json > myemoji.txt

# Prints out a text file containing only the Emoji characters
# listed in the input JSON file.
# The purpose of this was to provide a list of characters to
# make a subset of a web font to display just these characters.
#
# (Also contains commented-out code to find ranges for specifying the
# unicode-range to use in the CSS @font-face rule.)
#
# For more, see
# https://ratfactor.com/cards/make-a-webfont-subset

fin = ARGV[0]

json = File.read(fin)
list = JSON.parse(json)

weelist = list.map do |e|
  e['emoji']
end

#puts JSON.generate(weelist)

outstr = weelist.join('');

puts outstr

# BAD CODE ALERT!
# really low-effort and "low-resolution" range finding
#last = 0
#outstr.codepoints.sort.each do |c|
#    if c - last > 500
#        puts last.to_s(16)
#        puts "#{c.to_s(16)}..."
#    end
#    last = c
#end
#puts last.to_s(16)
