Class: YouPlot::Command

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ Command

Returns a new instance of Command.



18
19
20
21
22
23
24
25
# File 'lib/youplot/command.rb', line 18

def initialize(argv = ARGV)
  @argv    = argv
  @parser  = Parser.new
  @command = nil
  @params  = nil
  @options = nil
  @backend = YouPlot::Backends::UnicodePlot
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



15
16
17
# File 'lib/youplot/command.rb', line 15

def command
  @command
end

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/youplot/command.rb', line 16

def data
  @data
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/youplot/command.rb', line 15

def options
  @options
end

#paramsObject

Returns the value of attribute params.



15
16
17
# File 'lib/youplot/command.rb', line 15

def params
  @params
end

#parserObject (readonly)

Returns the value of attribute parser.



16
17
18
# File 'lib/youplot/command.rb', line 16

def parser
  @parser
end

Instance Method Details

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/youplot/command.rb', line 32

def run
  parser.parse_options(@argv)
  @command ||= parser.command
  @options ||= parser.options
  @params  ||= parser.params

  # color command
  if %i[colors color colours colour].include? @command
    plot = create_plot
    output_plot(plot)
    return
  end

  # progressive mode
  if options[:progressive]
    run_progressive

  # normal mode
  else
    # Sometimes the input file does not end with a newline code.
    begin
      begin
        input = Kernel.gets(nil)
      rescue Errno::ENOENT => e
        warn e.message
        next
      end
      main(input)
    end until input
  end
end

#run_as_executableObject



27
28
29
30
# File 'lib/youplot/command.rb', line 27

def run_as_executable
  YouPlot.run_as_executable = true
  run
end