require 'gemoji-parser'

def rx(regex, desc)
  "# RegExp for matching #{desc}\n# generated by gemoji-parser\n\n/#{regex.to_s[7..-2]}/"
end

def w(fp)
  "write: #{fp}"
end

namespace :output do
  namespace :regex do
    
    desc 'Outputs generated unicode regex'
    task :unicode do
      fp = 'output/rx_unicode.rb'
      f = File.open(fp, 'w')
      f.puts rx EmojiParser.unicode_regex, 'emoji unicode'
      f.close
      puts w(fp)
    end

    desc 'Outputs generated tokens regex'
    task :token do
      fp = 'output/rx_token.rb'
      f = File.open(fp, 'w')
      f.puts rx EmojiParser.token_regex, 'emoji token strings'
      f.close
      puts w(fp)
    end

    desc 'Outputs generated emoticons regex'
    task :emoticon do
      fp = 'output/rx_emoticon.rb'
      f = File.open(fp, 'w')
      f.puts rx EmojiParser.emoticon_regex, 'basic emoticons'
      f.close
      puts w(fp)
    end

    desc 'Outputs generated macro regex for multiple symbol types'
    task :macro do
      fp = 'output/rx_macro.rb'
      f = File.open(fp, 'w')
      f.puts rx EmojiParser.macro_regex, 'emoji unicode, tokens, and emoticons'
      f.close
      puts w(fp)
    end

    desc 'Outputs all generated regexs'
    task :all do
      Rake::Task["output:regex:unicode"].invoke
      Rake::Task["output:regex:token"].invoke
      Rake::Task["output:regex:emoticon"].invoke
      Rake::Task["output:regex:macro"].invoke
    end
    
  end
end