Class: Natas
- Inherits:
-
Object
- Object
- Natas
- Defined in:
- lib/natas.rb
Overview
OverTheWire wargame Natas
Constant Summary collapse
- MAXLEVEL =
34
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#levels ⇒ Object
Returns the value of attribute levels.
Instance Method Summary collapse
- #exec ⇒ Object
-
#initialize(shell) ⇒ Natas
constructor
A new instance of Natas.
- #to_yaml ⇒ Object
Constructor Details
#initialize(shell) ⇒ Natas
Returns a new instance of Natas.
16 17 18 19 20 21 22 |
# File 'lib/natas.rb', line 16 def initialize(shell) @shell = shell @level = nil @levels = [] ObjectSpace.each_object(Class).select { |c| c < NatasLevelBase }.each { |c| @levels << c.new(@shell) } @levels.sort! { |a, b| a.level <=> b.level } end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
14 15 16 |
# File 'lib/natas.rb', line 14 def level @level end |
#levels ⇒ Object
Returns the value of attribute levels.
14 15 16 |
# File 'lib/natas.rb', line 14 def levels @levels end |
Instance Method Details
#exec ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/natas.rb', line 24 def exec level = @levels.detect { |l| l.level == @level } raise StandardError, "Level #{@level} not implemented" if level.nil? raise StandardError, "Level #{@level} has no password" if level.password.nil? password = level.exec level = @levels.detect { |l| l.level == @level + 1 } return if level.nil? level.password = password end |
#to_yaml ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/natas.rb', line 37 def to_yaml data = {} @levels.each do |level| data[level.level] = level.password end YAML.dump(data) end |