Class: Termplot::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/termplot/options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



23
24
25
26
27
# File 'lib/termplot/options.rb', line 23

def initialize
  self.class.default_options.each do |(option, value)|
    instance_variable_set("@#{option}", value)
  end
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



11
12
13
# File 'lib/termplot/options.rb', line 11

def color
  @color
end

#colsObject (readonly)

Returns the value of attribute cols.



11
12
13
# File 'lib/termplot/options.rb', line 11

def cols
  @cols
end

#commandObject (readonly)

Returns the value of attribute command.



11
12
13
# File 'lib/termplot/options.rb', line 11

def command
  @command
end

#debugObject (readonly)

Returns the value of attribute debug.



11
12
13
# File 'lib/termplot/options.rb', line 11

def debug
  @debug
end

#fileObject (readonly)

Returns the value of attribute file.



11
12
13
# File 'lib/termplot/options.rb', line 11

def file
  @file
end

#full_screenObject (readonly)

Returns the value of attribute full_screen.



11
12
13
# File 'lib/termplot/options.rb', line 11

def full_screen
  @full_screen
end

#intervalObject (readonly)

Returns the value of attribute interval.



11
12
13
# File 'lib/termplot/options.rb', line 11

def interval
  @interval
end

#line_styleObject (readonly)

Returns the value of attribute line_style.



11
12
13
# File 'lib/termplot/options.rb', line 11

def line_style
  @line_style
end

#rowsObject (readonly)

Returns the value of attribute rows.



11
12
13
# File 'lib/termplot/options.rb', line 11

def rows
  @rows
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/termplot/options.rb', line 11

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/termplot/options.rb', line 11

def type
  @type
end

Class Method Details

.default_optionsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/termplot/options.rb', line 40

def self.default_options
  {
    # General options
    rows: 19,
    cols: 100,
    full_screen: false,
    debug: false,

    # Input modes
    file: nil,
    command: nil,
    interval: 1000,

    # Widget (only necessary for stdin/command input modes)
    type: "timeseries",

    # General - All/multiple widget types
    title: "Series",
    color: "green",

    # Timeseries
    line_style: "heavy-line",
  }
end

Instance Method Details

#input_modeObject

3 input modes supported:

  • Read from stdin and render a single chart (default)

  • Run a single command at an interval and render a single chart

  • Read configuration from a file, run multiple commands at an interval and render multiple charts in a dashboard



34
35
36
37
38
# File 'lib/termplot/options.rb', line 34

def input_mode
  return :file    unless @file.nil?
  return :command unless @command.nil?
  :stdin
end

#parse_options!Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/termplot/options.rb', line 72

def parse_options!
  # Debug option is parsed manually to prevent it from showing up in the
  # options help
  parse_debug

  OptionParser.new do |opts|
    opts.banner = "Usage: termplot [OPTIONS]"

    parse_rows(opts)
    parse_cols(opts)
    parse_full_screen(opts)

    parse_file(opts)
    parse_command(opts)
    parse_interval(opts)

    parse_type(opts)

    parse_title(opts)
    parse_color(opts)

    parse_line_style(opts)

    opts.on("-h", "--help", "Display this help message") do
      puts opts
      exit(0)
    end

  end.parse!
  self
end

#producer_optionsObject



104
105
106
# File 'lib/termplot/options.rb', line 104

def producer_options
  ProducerOptions.new(command: command, interval: interval)
end

#to_hObject



65
66
67
68
69
70
# File 'lib/termplot/options.rb', line 65

def to_h
  self.class.default_options.inject({}) do |hash, (k, _)|
    hash[k] = instance_variable_get("@#{k}")
    hash
  end
end