Class: Daigaku::Solution
- Inherits:
-
Object
- Object
- Daigaku::Solution
- Defined in:
- lib/daigaku/solution.rb
Constant Summary collapse
- FILE_SUFFIX =
'_solution.rb'.freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(unit_path) ⇒ Solution
constructor
A new instance of Solution.
- #store_key ⇒ Object
- #verified? ⇒ Boolean
- #verify! ⇒ Object
Constructor Details
#initialize(unit_path) ⇒ Solution
Returns a new instance of Solution.
7 8 9 10 11 12 |
# File 'lib/daigaku/solution.rb', line 7 def initialize(unit_path) @unit_path = unit_path @path = solution_path(unit_path) @code = File.read(@path).strip if File.file?(@path) @verified = store_state end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/daigaku/solution.rb', line 5 def code @code end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/daigaku/solution.rb', line 5 def errors @errors end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/daigaku/solution.rb', line 5 def path @path end |
Instance Method Details
#store_key ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/daigaku/solution.rb', line 24 def store_key unless @store_key part_path = path.split('/')[-3..-1].join('/').gsub(FILE_SUFFIX, '') @store_key = Storeable.key(part_path, prefix: 'verified') end @store_key end |
#verified? ⇒ Boolean
20 21 22 |
# File 'lib/daigaku/solution.rb', line 20 def verified? !!@verified end |
#verify! ⇒ Object
14 15 16 17 18 |
# File 'lib/daigaku/solution.rb', line 14 def verify! result = Daigaku::Test.new(@unit_path).run(code) self.store_state = result.passed? result end |