Class: Kor::Output::Ltsv

Inherits:
Object
  • Object
show all
Defined in:
lib/kor/output/ltsv.rb,
lib/kor/output/ltsv/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Ltsv

Returns a new instance of Ltsv.



4
5
6
7
8
# File 'lib/kor/output/ltsv.rb', line 4

def initialize(io)
  @io = io
  @keys = []
  @prekeys = nil
end

Instance Method Details

#finishObject



30
31
# File 'lib/kor/output/ltsv.rb', line 30

def finish
end

#head(keys) ⇒ Object



16
17
18
# File 'lib/kor/output/ltsv.rb', line 16

def head(keys)
  @keys = keys
end

#parse(opt) ⇒ Object



10
11
12
13
14
# File 'lib/kor/output/ltsv.rb', line 10

def parse(opt)
  opt.on("--key=KEY", "preset keys (e.g. foo,bar,baz) (default auto)") do |arg|
    @prekeys = arg
  end
end

#puts(values) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/kor/output/ltsv.rb', line 20

def puts(values)
  if @prekeys
    @io.puts @prekeys.split(",").map { |key|
      "#{key}:#{values[@keys.index(key)]}"
    }.join("\t")
  else
    @io.puts @keys.zip(values).map{ |(k,v)| "#{k}:#{v}" }.join("\t")
  end
end