Sha256: b938e81e6c17e96886353ba2801d65aba20ee09673924fe33e90abae1081c210
Contents?: true
Size: 1.73 KB
Versions: 3
Compression:
Stored size: 1.73 KB
Contents
require 'bundler/gem_tasks' require 'rspec/core/rake_task' require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) RuboCop::RakeTask.new task default: [:spec, :rubocop] task :generate_nextstep_mappings do require 'net/http' url = 'http://ftp.unicode.org/Public/MAPPINGS/VENDORS/NEXT/NEXTSTEP.TXT' mappings = Net::HTTP.get(URI(url)) .lines .grep(/^[^#$]/) .map { |l| l.split("\t", 3) } .reduce('') do |f, (ns, uc, cm)| f << " #{ns} => #{uc}, #{cm}" end map = <<-RUBY # frozen-string-literal: true module Nanaimo module Unicode # Taken from #{url} NEXT_STEP_MAPPING = { #{mappings} }.freeze end end RUBY File.open('lib/nanaimo/unicode/next_step_mapping.rb', 'w') { |f| f << map } end task :generate_quote_maps do quote_map = { "\a" => '\\a', "\b" => '\\b', "\f" => '\\f', "\r" => '\\r', "\t" => '\\t', "\v" => '\\v', "\n" => '\\n', %(') => "\\'", %(") => '\\"' } unquote_map = quote_map.each_with_object("\n" => "\n") do |(value, escaped), map| map[escaped[1..-1]] = value map end 0.upto(31) { |i| quote_map[[i].pack('U')] ||= format('\\U%04x', i) } quote_regexp = Regexp.union(quote_map.keys) dump_hash = proc do |hash, indent = 4| hash.reduce("{\n") { |dumped, (k, v)| dumped << "#{' ' * (indent + 2)}#{k.dump} => #{v.dump},\n" } << ' ' * indent << '}.freeze' end map = <<-RUBY # frozen-string-literal: true module Nanaimo module Unicode QUOTE_MAP = #{dump_hash[quote_map]} UNQUOTE_MAP = #{dump_hash[unquote_map]} QUOTE_REGEXP = #{quote_regexp.inspect} end end RUBY File.open('lib/nanaimo/unicode/quote_maps.rb', 'w') { |f| f << map } end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nanaimo-0.1.2 | Rakefile |
nanaimo-0.1.1 | Rakefile |
nanaimo-0.1.0 | Rakefile |