Skip to content

Instantly share code, notes, and snippets.

@thbwd
Created January 2, 2020 14:11
Show Gist options
  • Save thbwd/28388bc3cb60f59dbc2b1a0df599da7a to your computer and use it in GitHub Desktop.
Save thbwd/28388bc3cb60f59dbc2b1a0df599da7a to your computer and use it in GitHub Desktop.
def i(str)
return '' if str.nil? || (stripped = str.strip).empty?
"🧲#{stripped}🧲"
end
def convert(input)
input.gsub(/πŸͺ([^πŸ”€πŸͺ]+)?((πŸ”€([^πŸ”€πŸͺ]+)πŸ”€([^πŸ”€πŸͺ]+)?)+)πŸͺ/) do
m = Regexp.last_match
s = "πŸ”€#{i m[1]}"
m[2].scan(/πŸ”€([^πŸ”€πŸͺ]+)πŸ”€([^πŸ”€πŸͺ]+)?/).each { |l, e| s << l << i(e) }
s << 'πŸ”€'
end
end
Dir['*.emojic'].each do |file_name|
puts file_name
converted = convert(File.read(file_name))
File.open(file_name, 'w') { |file| file.puts converted }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment