Class: Daigaku::Solution
- Inherits:
-
Object
- Object
- Daigaku::Solution
- Defined in:
- lib/daigaku/solution.rb
Constant Summary collapse
- FILE_SUFFIX =
'_solution.rb'
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.
8 9 10 11 12 13 |
# File 'lib/daigaku/solution.rb', line 8 def initialize(unit_path) @unit_path = unit_path @path = solution_path(unit_path) @code = File.read(@path).strip if File.file?(@path) @verified = get_store_state end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/daigaku/solution.rb', line 6 def code @code end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/daigaku/solution.rb', line 6 def errors @errors end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/daigaku/solution.rb', line 6 def path @path end |
Instance Method Details
#store_key ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/daigaku/solution.rb', line 25 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
21 22 23 |
# File 'lib/daigaku/solution.rb', line 21 def verified? !!@verified end |
#verify! ⇒ Object
15 16 17 18 19 |
# File 'lib/daigaku/solution.rb', line 15 def verify! result = Daigaku::Test.new(@unit_path).run(self.code) set_store_state(result.passed?) result end |