module Kernel

Constants

CSV_BOM

Public Instance Methods

generate_csv(filename, **options, &block) click to toggle source
# File lib/arql/ext/kernel.rb, line 71
def generate_csv(filename, **options, &block)
  opts = {
    col_sep: "\t",
    row_sep: "\r\n"
  }
  opts.merge!(options.except(:encoding))
  encoding = options[:encoding] || 'UTF-16LE'
  File.open(File.expand_path(filename), "w:#{encoding}") do |file|
    file.write(CSV_BOM)
    file.write CSV.generate(**opts, &block)
  end
end
generate_excel(filename) { |workbook| ... } click to toggle source
# File lib/arql/ext/kernel.rb, line 95
def generate_excel(filename)
  Axlsx::Package.new do |package|
    yield(package.workbook)
    package.serialize(File.expand_path(filename))
  end
end
models() click to toggle source
# File lib/arql/commands/models.rb, line 37
def models
  Arql::Commands::Models::models
end
parse_csv(filename, **options) click to toggle source
# File lib/arql/ext/kernel.rb, line 84
def parse_csv(filename, **options)
  encoding = options[:encoding] || 'UTF-16'
  opts = {
    headers: false,
    col_sep: "\t",
    row_sep: "\r\n"
  }
  opts.merge!(options.except(:encoding))
  CSV.parse(IO.read(File.expand_path(filename), encoding: encoding, binmode: true).encode('UTF-8'), **opts).to_a
end
parse_excel(filename) click to toggle source
# File lib/arql/ext/kernel.rb, line 102
def parse_excel(filename)
  xlsx = Roo::Excelx.new(File.expand_path(filename))
  xlsx.sheets.each_with_object({}) do |sheet_name, result|
    begin
      result[sheet_name] = xlsx.sheet(sheet_name).to_a
    rescue
    end
  end
end
print_tables(format = :md) click to toggle source
sql(sql) click to toggle source
# File lib/arql/ext/kernel.rb, line 7
def sql(sql)
  ActiveRecord::Base.connection.exec_query(sql)
end
table(name) click to toggle source
# File lib/arql/commands/table.rb, line 52
def table(name)
  Arql::Commands::Table::table_info(Arql::Commands::Table::get_table_name(name))
end
tables() click to toggle source
# File lib/arql/commands/models.rb, line 41
def tables
  models
end