Class: KiFormat::Command
- Inherits:
-
Object
- Object
- KiFormat::Command
- Defined in:
- lib/ki_format/command.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(input = $stdin, output = $stdout, error = $stderr) ⇒ Command
constructor
A new instance of Command.
- #print_keys ⇒ Object
- #print_list ⇒ Object
- #print_pretty ⇒ Object
- #print_selected(*keys) ⇒ Object
- #print_table(*keys) ⇒ Object
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
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/ki_format/command.rb', line 5 def error @error end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
5 6 7 |
# File 'lib/ki_format/command.rb', line 5 def input @input end |
#output ⇒ Object (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
#print_keys ⇒ Object
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 |
#print_list ⇒ Object
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 |
#print_pretty ⇒ Object
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 |
#print_selected(*keys) ⇒ Object
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 |
#print_table(*keys) ⇒ Object
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 |