quran-json/bin/sql/create-sql-seed-file

22 lines
671 B
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
##
# This script is responsible for the creation "src/sql/seed.sql" -
# a SQL file that contains the contents of The Qur'an in Arabic,
# and as translations in English, Portuguese and Farsi. The
# "src/json/" directory is used as the data source.
##
# Dependencies
require "json"
require "erb"
require_relative "../../binlib/sql"
base_dir = File.join("src", "sql")
template = File.read File.join(base_dir, "seed.sql.erb")
result = ERB.new(template)
.result(SQL::Template.context)
.each_line.map(&:strip)
.reject(&:empty?).join($/)
File.write File.join(base_dir, "seed.sql"), result