Class: Kor::Output::Ltsv
- Inherits:
-
Object
- Object
- Kor::Output::Ltsv
- Defined in:
- lib/kor/output/ltsv.rb,
lib/kor/output/ltsv/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #finish ⇒ Object
- #head(keys) ⇒ Object
-
#initialize(io) ⇒ Ltsv
constructor
A new instance of Ltsv.
- #parse(opt) ⇒ Object
- #puts(values) ⇒ Object
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
#finish ⇒ Object
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 |