Class: Kor::Output::Markdown

Inherits:
Base
  • Object
show all
Defined in:
lib/kor/output/markdown.rb

Instance Method Summary collapse

Methods inherited from Base

#finish, #initialize, #io

Constructor Details

This class inherits a constructor from Kor::Output::Base

Instance Method Details

#head(keys) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kor/output/markdown.rb', line 14

def head(keys)
  if @select_key
    select_keys = @select_key.split(",")
    select_keys.select!{ |key| keys.include?(key) }
    @select_key = select_keys.map do |key|
      keys.index(key)
    end
    keys = select_keys
  end
  s = @space || " "
  io.puts "|#{s}#{keys.join("#{s}|#{s}")}#{s}|"
  io.puts "|#{s}#{(["---"] * keys.length).join("#{s}|#{s}")}#{s}|"
end

#parse(opt) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/kor/output/markdown.rb', line 4

def parse(opt)
  @space = " "
  opt.on("--strip", "strip space") do |arg|
    @space = ""
  end
  opt.on("--key=KEY", "select output keys (like foo,bar,baz)") do |arg|
    @select_key = arg
  end
end

#puts(values) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/kor/output/markdown.rb', line 28

def puts(values)
  if @select_key
    s = @space || " "
    io.puts "|#{s}#{@select_key.map{ |index| values[index] }.join("#{s}|#{s}")}#{s}|"
  else
    s = @space || " "
    io.puts "|#{s}#{values.join("#{s}|#{s}")}#{s}|"
  end
end