Class: Dbtools::Convert

Inherits:
Thor
  • Object
show all
Defined in:
lib/tasks/convert.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Convert

Returns a new instance of Convert.



9
10
11
# File 'lib/tasks/convert.rb', line 9

def initialize(*args)
  super
end

Instance Method Details

#csv2rdf(csv_file, uri, output_file = nil, compressed = false) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tasks/convert.rb', line 62

def csv2rdf(csv_file, uri, output_file=nil, compressed=false)
  csv_rdf = Dbtools::Converter::Csv2rdf_converter.new(csv_file, uri)
  if output_file.nil?
    csv_rdf.each_triple do |triple|
      puts triple
    end
  else
    begin
      file = if compressed
               Zlib::GzipWriter.open(output_file + '.gz')
             else
               File.open(output_file, 'w')
             end
      csv_rdf.each_triple do |triple|
        file.write(triple << "\n")
      end
    ensure
      file.close unless file.nil?
    end
  end
end

#excel2csv(excel_file, sheet_index = 0, output_file = nil) ⇒ Object

option :sheet,



34
35
36
37
38
39
40
41
42
43
# File 'lib/tasks/convert.rb', line 34

def excel2csv(excel_file, sheet_index = 0, output_file = nil)
  converter = Dbtools::Converter::Excel2csv_converter.new(excel_file)
  if output_file.nil?
    STDOUT << converter.sheet2csv(sheet_index)
  else
    File.open(output_file, 'a') do |f|
      f << converter.sheet2csv(sheet_index)
    end
  end
end

#googledrive2rdf(file_id, output_file = nil, compressed = false) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/tasks/convert.rb', line 96

def googledrive2rdf(file_id, output_file=nil, compressed=false)
  output_dir = File.join('/tmp', 'dbtools_googledrive/')
  file_path = invoke("dbtools:google_drive:download", [file_id, output_dir])
  uri = "https://drive.google.com/open?id=" << file_id
  invoke "dbtools:convert:csv2rdf", [file_path, uri, output_file, compressed]
ensure
  FileUtils.remove_entry_secure(output_dir)
end