Sha256: 7df18e6b9e3d75e7204e7c94da6fed249757dd946fa4198d4763213c19137714

Contents?: true

Size: 728 Bytes

Versions: 1

Compression:

Stored size: 728 Bytes

Contents

require 'csv'

module Arql
  class VD
    COMMAND = 'vd'

    attr_accessor :rows

    def initialize
      return unless check_command_installation
      @rows = []
      yield self
      command = "#{COMMAND} -f csv"
      IO.popen(command, 'w+') do |io|
        io.puts(csv)
        io.close_write
      end
      print "\033[5q"
    end

    def <<(row)
      rows << row
    end

    def csv
      CSV.generate do |csv|
        rows.each do |row|
          csv << row
        end
      end
    end

    def check_command_installation
      `which #{COMMAND}`
      if $?.exitstatus != 0
        puts "Please install vd (visidata) command, see: https://www.visidata.org/"
      else
        true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arql-0.3.8 lib/arql/vd.rb