Class: Zeusd::Interpreter
- Inherits:
-
Object
- Object
- Zeusd::Interpreter
- Defined in:
- lib/zeusd/interpreter.rb
Defined Under Namespace
Classes: Line
Constant Summary collapse
- STATES =
%w[ready crashed running connecting waiting]
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#last_status ⇒ Object
readonly
Returns the value of attribute last_status.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#state_colors ⇒ Object
readonly
Returns the value of attribute state_colors.
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(*args) ⇒ Interpreter
constructor
A new instance of Interpreter.
- #last_update ⇒ Object
- #translate(zeus_output) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Interpreter
Returns a new instance of Interpreter.
9 10 11 12 13 14 |
# File 'lib/zeusd/interpreter.rb', line 9 def initialize(*args) @state_colors = Hash[STATES.zip([nil]*STATES.length)] @commands = {} @errors = [] @lines = [] end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
6 7 8 |
# File 'lib/zeusd/interpreter.rb', line 6 def commands @commands end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/zeusd/interpreter.rb', line 6 def errors @errors end |
#last_status ⇒ Object (readonly)
Returns the value of attribute last_status.
7 8 9 |
# File 'lib/zeusd/interpreter.rb', line 7 def last_status @last_status end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
5 6 7 |
# File 'lib/zeusd/interpreter.rb', line 5 def lines @lines end |
#state_colors ⇒ Object (readonly)
Returns the value of attribute state_colors.
6 7 8 |
# File 'lib/zeusd/interpreter.rb', line 6 def state_colors @state_colors end |
Instance Method Details
#complete? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/zeusd/interpreter.rb', line 41 def complete? return false if errors.any? return true if commands.all? {|command, status| %[crashed ready].include?(status)} false end |
#last_update ⇒ Object
47 48 49 |
# File 'lib/zeusd/interpreter.rb', line 47 def last_update @lines[@lines.rindex(&:update?)..-1].join("\n").to_s end |
#translate(zeus_output) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zeusd/interpreter.rb', line 16 def translate(zeus_output) zeus_output.split("\n").map{|x| Line.new(x) }.each do |line| # State Colors if @state_colors.values.any?(&:nil?) && line.state_legend? STATES.each do |state| state_colors[state] = line.color_of(state) end end # Errors @errors << line if line.color == state_colors["crashed"] # Commands @commands[line.command[:name]] = state_colors.invert[line.command[:color]] if line.command? # Add Line @lines << line end # Garbage Collection if @lines.length > 100 @lines = @lines.last(100) end end |