Class: Xxx2json::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/xxx2json/cli.rb

Instance Method Summary collapse

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 = [], options = {}, config = {})
  super(args, options, config)
  @global_options = config[:shell].base.options
  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

#csvObject



24
25
26
# File 'lib/xxx2json/cli.rb', line 24

def csv
  puts_json @core.convert_csv(@buffer, ',', options['headers'])
end

#ltsvObject



46
47
48
# File 'lib/xxx2json/cli.rb', line 46

def ltsv
  puts_json LTSV.parse(@buffer)
end

#regexpObject



52
53
54
# File 'lib/xxx2json/cli.rb', line 52

def regexp
  puts_json @core.convert_regexp(@buffer, options['format'])
end

#rssObject



57
58
59
# File 'lib/xxx2json/cli.rb', line 57

def rss
  puts_json @core.convert_rss(@buffer)
end

#spaceObject



30
31
32
# File 'lib/xxx2json/cli.rb', line 30

def space
  puts_json @core.convert_csv(@buffer, ' ', options['headers'])
end

#tsvObject



36
37
38
# File 'lib/xxx2json/cli.rb', line 36

def tsv
  puts_json @core.convert_csv(@buffer, "\t", options['headers'])
end

#versionObject



62
63
64
# File 'lib/xxx2json/cli.rb', line 62

def version
  puts VERSION
end

#yamlObject



41
42
43
# File 'lib/xxx2json/cli.rb', line 41

def yaml
  puts_json YAML.load(@buffer)
end