-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
40 lines (36 loc) · 1.12 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'bundler'
require "bundler/gem_tasks"
require "open-uri"
Bundler.require
task :default => [:spec]
require 'rspec/core/rake_task'
desc "Run specs"
RSpec::Core::RakeTask.new do |t|
t.rspec_opts = %w(-fd --color)
end
desc "Rebuild with latest area code mappings from e164.js"
task :rebuild do
# Update mappings
js_mappings = open('https://raw.githubusercontent.com/remind101/e164.js/master/e164.js').read
mappings = js_mappings.scan(/"([\d]+)\": \[\s*(.+?)\s*\],/)
lookup_file = File.open('lib/e164/lookuptable.rb', 'w')
lookup_file.write('# This file is automatically generated by `rake rebuild`
module E164
LookupTable = {
')
for mapping in mappings
lookup_file.write(" \"#{mapping[0]}\" => [#{mapping[1]}],\n")
end
lookup_file.write(' }
end')
lookup_file.close()
# Sync up version
js_manifest = open('https://raw.githubusercontent.com/remind101/e164.js/master/package.json').read
version = js_manifest.match(/version":\s*"([\d.]+)"/).captures[0]
version_file = File.open('lib/e164/version.rb', 'w')
version_file.write("module E164
VERSION = \"#{version}\"
end
")
version_file.close()
end