-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRakefile
More file actions
49 lines (39 loc) · 1.25 KB
/
Copy pathRakefile
File metadata and controls
49 lines (39 loc) · 1.25 KB
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
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
require 'rake/testtask'
require 'bundler/gem_tasks'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/test_*.rb']
end
desc 'Run tests'
task default: :test
desc 'Update Unicode Data files'
task :ucd do
require 'net/http'
derived_name = 'https://www.unicode.org/Public/UCD/latest/ucd/extracted/DerivedName.txt'
blocks = 'https://www.unicode.org/Public/UCD/latest/ucd/Blocks.txt'
files = [derived_name, blocks]
files.each do |file|
filename = File.basename(URI(file).path)
download(file, File.join(__dir__, "data/#{filename}"))
puts "[+] Updated data/#{filename}"
end
end
## Utils ##
def download(url, dest_path)
uri = URI.parse(url)
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new(uri)
http.request(request) do |response|
raise "Failed (#{response.code})" unless response.is_a?(Net::HTTPSuccess)
# Open the destination file in write‑binary mode.
# This truncates the file if it already exists, effectively overwriting it.
File.open(dest_path, 'wb') do |file|
response.read_body do |chunk|
file.write(chunk)
end
end
end
end
end