Class: Termplot::Options
- Inherits:
-
Object
- Object
- Termplot::Options
- Defined in:
- lib/termplot/options.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#full_screen ⇒ Object
readonly
Returns the value of attribute full_screen.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#line_style ⇒ Object
readonly
Returns the value of attribute line_style.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
-
#input_mode ⇒ Object
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.
- #parse_options! ⇒ Object
- #producer_options ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
23 24 25 26 27 |
# File 'lib/termplot/options.rb', line 23 def initialize self.class..each do |(option, value)| instance_variable_set("@#{option}", value) end end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def color @color end |
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def cols @cols end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def command @command end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def debug @debug end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def file @file end |
#full_screen ⇒ Object (readonly)
Returns the value of attribute full_screen.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def full_screen @full_screen end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def interval @interval end |
#line_style ⇒ Object (readonly)
Returns the value of attribute line_style.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def line_style @line_style end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def rows @rows end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
11 12 13 |
# File 'lib/termplot/options.rb', line 11 def title @title end |
#type ⇒ Object (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_options ⇒ Object
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. { # 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_mode ⇒ Object
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 # Debug option is parsed manually to prevent it from showing up in the # options help parse_debug OptionParser.new do |opts| opts. = "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_options ⇒ Object
104 105 106 |
# File 'lib/termplot/options.rb', line 104 def ProducerOptions.new(command: command, interval: interval) end |
#to_h ⇒ Object
65 66 67 68 69 70 |
# File 'lib/termplot/options.rb', line 65 def to_h self.class..inject({}) do |hash, (k, _)| hash[k] = instance_variable_get("@#{k}") hash end end |