Class: Json2xxx::CLI
- Inherits:
-
Thor
- Object
- Thor
- Json2xxx::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/json2xxx/cli.rb
Instance Method Summary collapse
- #backlog ⇒ Object
- #csv ⇒ Object
- #delimiter(delim) ⇒ Object
- #excel ⇒ Object
- #hash ⇒ Object
- #html ⇒ Object
-
#initialize(args = [], options = {}, config = {}) ⇒ CLI
constructor
A new instance of CLI.
- #markdown ⇒ Object
- #tsv ⇒ Object
- #yaml ⇒ Object
Constructor Details
#initialize(args = [], options = {}, config = {}) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/json2xxx/cli.rb', line 13 def initialize(args = [], = {}, config = {}) super(args, , config) @global_options = config[:shell].base. return unless File.pipe?(STDIN) @data = parse_json(STDIN.read) @core = Core.new if @global_options['fields'] @data = @core.extract(@data, @global_options['fields']) end if @global_options['sort'] @data = @core.sort(@data, @global_options['sort']) end end |
Instance Method Details
#backlog ⇒ Object
59 60 61 |
# File 'lib/json2xxx/cli.rb', line 59 def backlog puts @core.convert_backlog_wiki(@data) end |
#csv ⇒ Object
44 45 46 |
# File 'lib/json2xxx/cli.rb', line 44 def csv puts @core.convert_csv(@data, ',', ['force_quotes'], ['write_header']) end |
#delimiter(delim) ⇒ Object
30 31 32 |
# File 'lib/json2xxx/cli.rb', line 30 def delimiter(delim) puts @core.convert_csv(@data, delim, ['force_quotes'], ['write_header']) end |
#excel ⇒ Object
75 76 77 |
# File 'lib/json2xxx/cli.rb', line 75 def excel @core.convert_excel(@data, ['output']) end |
#hash ⇒ Object
69 70 71 |
# File 'lib/json2xxx/cli.rb', line 69 def hash ap @data, indent: 2, index: false end |
#html ⇒ Object
64 65 66 |
# File 'lib/json2xxx/cli.rb', line 64 def html puts @core.convert_html(@data) end |
#markdown ⇒ Object
54 55 56 |
# File 'lib/json2xxx/cli.rb', line 54 def markdown puts @core.convert_markdown(@data) end |
#tsv ⇒ Object
37 38 39 |
# File 'lib/json2xxx/cli.rb', line 37 def tsv puts @core.convert_csv(@data, "\t", ['force_quotes'], ['write_header']) end |
#yaml ⇒ Object
49 50 51 |
# File 'lib/json2xxx/cli.rb', line 49 def yaml puts YAML.dump(@data) end |