Task 18.2 - echo string challenge selecting based on difficulty. low.rb implemented.

This commit is contained in:
thomashaw
2018-08-10 16:43:48 +01:00
committed by ts
parent 7b75aa2b85
commit e0057bd3d0
6 changed files with 32 additions and 2 deletions

View File

@@ -3,6 +3,8 @@
require_relative 'local_script_challenge_generator.rb'
class RubyChallengeGenerator < ScriptChallengeGenerator
attr_accessor :difficulty
def initialize
super
self.module_name = 'Ruby Example Script Generator'

View File

@@ -14,6 +14,7 @@ class ScriptChallengeGenerator
attr_accessor :module_name
attr_accessor :has_base64_inputs
attr_accessor :outputs
attr_accessor :difficulty
# override this
def initialize
@@ -21,6 +22,7 @@ class ScriptChallengeGenerator
self.module_name = 'Null generator'
self.has_base64_inputs = false
self.outputs = []
self.difficulty = ''
end
# override this
@@ -51,7 +53,8 @@ class ScriptChallengeGenerator
def get_options_array
[['--help', '-h', GetoptLong::NO_ARGUMENT],
['--b64', GetoptLong::OPTIONAL_ARGUMENT]]
['--b64', GetoptLong::OPTIONAL_ARGUMENT],
['--difficulty', GetoptLong::OPTIONAL_ARGUMENT]]
end
# Override this when using read_fact's in your module. Always call super first
@@ -67,6 +70,9 @@ class ScriptChallengeGenerator
usage
when '--b64'
# do nothing
when '--difficulty'
self.difficulty << arg
end
end

View File

@@ -9,7 +9,7 @@ class EchoStringChallenge < RubyChallengeGenerator
end
def challenge_content
File.read(File.join(File.dirname(__FILE__), 'challenge.rb'))
File.read(File.join(File.dirname(__FILE__), "#{difficulty}.rb"))
end
end

View File

@@ -15,6 +15,15 @@
<platform>linux</platform>
<platform>windows</platform>
<read_fact>difficulty</read_fact>
<default_input into="difficulty">
<value>low</value>
<!--TODO: implement higher difficulty options -->
<!--<value>medium</value>-->
<!--<value>high</value>-->
</default_input>
<output_type>script</output_type>
</generator>

View File

@@ -13,6 +13,19 @@
<platform>linux</platform>
<platform>windows</platform>
<!-- Some script challenges can take a difficulty parameter. -->
<!-- Valid inputs are: low, medium, high -->
<!--<read_fact>difficulty</read_fact>-->
<!--<default_input into="difficulty">-->
<!--<value>low</value>-->
<!--<value>medium</value>-->
<!--<value>high</value>-->
<!--</default_input>-->
<output_type>script</output_type>
</generator>