Class: KiFormat::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ki_format/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, output = $stdout, error = $stderr) ⇒ Command

Returns a new instance of Command.



7
8
9
10
11
# File 'lib/ki_format/command.rb', line 7

def initialize(input=$stdin, output=$stdout, error=$stderr)
  @input = input
  @output = output
  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



5
6
7
# File 'lib/ki_format/command.rb', line 5

def error
  @error
end

#inputObject (readonly)

Returns the value of attribute input.



5
6
7
# File 'lib/ki_format/command.rb', line 5

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



5
6
7
# File 'lib/ki_format/command.rb', line 5

def output
  @output
end

Instance Method Details



19
20
21
22
23
# File 'lib/ki_format/command.rb', line 19

def print_keys
  json_in do |data|
    ObjectSet.merged_keys(data).join("\n")
  end
end


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

def print_list
  json_in do |data|
    data.map do |obj|
      MultiJson.dump(obj, :pretty => false)
    end.join("\n")
  end
end


13
14
15
16
17
# File 'lib/ki_format/command.rb', line 13

def print_pretty
  json_in(false) do |data|
    MultiJson.dump(data, :pretty => true)
  end
end


39
40
41
42
43
# File 'lib/ki_format/command.rb', line 39

def print_selected(*keys)
  json_in do |data|
    TableMaker.new(data, :only => keys).print(:plain => true)
  end
end


33
34
35
36
37
# File 'lib/ki_format/command.rb', line 33

def print_table(*keys)
  json_in do |data|
    TableMaker.new(data, :only => keys).print
  end
end