Class: Xxx2json::CLI
- Inherits:
-
Thor
- Object
- Thor
- Xxx2json::CLI
- Defined in:
- lib/xxx2json/cli.rb
Instance Method Summary collapse
- #csv ⇒ Object
-
#initialize(args = [], options = {}, config = {}) ⇒ CLI
constructor
A new instance of CLI.
- #ltsv ⇒ Object
- #regexp ⇒ Object
- #rss ⇒ Object
- #space ⇒ Object
- #tsv ⇒ Object
- #version ⇒ Object
- #yaml ⇒ Object
Constructor Details
#initialize(args = [], options = {}, config = {}) ⇒ CLI
Returns a new instance of CLI.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/xxx2json/cli.rb', line 10 def initialize(args = [], = {}, config = {}) super(args, , config) @global_options = config[:shell].base. if @global_options['file'].nil? return unless File.pipe?(STDIN) @buffer = STDIN.read else @buffer = File.read(@global_options['file']) end @core = Core.new end |
Instance Method Details
#csv ⇒ Object
24 25 26 |
# File 'lib/xxx2json/cli.rb', line 24 def csv puts_json @core.convert_csv(@buffer, ',', ['headers']) end |
#ltsv ⇒ Object
46 47 48 |
# File 'lib/xxx2json/cli.rb', line 46 def ltsv puts_json LTSV.parse(@buffer) end |
#regexp ⇒ Object
52 53 54 |
# File 'lib/xxx2json/cli.rb', line 52 def regexp puts_json @core.convert_regexp(@buffer, ['format']) end |
#rss ⇒ Object
57 58 59 |
# File 'lib/xxx2json/cli.rb', line 57 def rss puts_json @core.convert_rss(@buffer) end |
#space ⇒ Object
30 31 32 |
# File 'lib/xxx2json/cli.rb', line 30 def space puts_json @core.convert_csv(@buffer, ' ', ['headers']) end |
#tsv ⇒ Object
36 37 38 |
# File 'lib/xxx2json/cli.rb', line 36 def tsv puts_json @core.convert_csv(@buffer, "\t", ['headers']) end |
#version ⇒ Object
62 63 64 |
# File 'lib/xxx2json/cli.rb', line 62 def version puts VERSION end |
#yaml ⇒ Object
41 42 43 |
# File 'lib/xxx2json/cli.rb', line 41 def yaml puts_json YAML.load(@buffer) end |