Class: Arql::VD

Inherits:
Object show all
Defined in:
lib/arql/vd.rb

Constant Summary collapse

COMMAND =
'vd'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ VD

Returns a new instance of VD.

Yields:

  • (_self)

Yield Parameters:

  • _self (Arql::VD)

    the object that the method was called on



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/arql/vd.rb', line 9

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[5 q"
end

Instance Attribute Details

#rowsObject

Returns the value of attribute rows.



7
8
9
# File 'lib/arql/vd.rb', line 7

def rows
  @rows
end

Instance Method Details

#<<(row) ⇒ Object



21
22
23
# File 'lib/arql/vd.rb', line 21

def <<(row)
  rows << row
end

#check_command_installationObject



33
34
35
36
37
38
39
40
# File 'lib/arql/vd.rb', line 33

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

#csvObject



25
26
27
28
29
30
31
# File 'lib/arql/vd.rb', line 25

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