Class: Daigaku::Solution

Inherits:
Object
  • Object
show all
Defined in:
lib/daigaku/solution.rb

Constant Summary collapse

FILE_SUFFIX =
'_solution.rb'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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      = load_code(@path)
  @verified  = store_state
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/daigaku/solution.rb', line 5

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/daigaku/solution.rb', line 5

def errors
  @errors
end

#pathObject (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_keyObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/daigaku/solution.rb', line 21

def verified?
  !!@verified
end

#verify!Object



14
15
16
17
18
19
# File 'lib/daigaku/solution.rb', line 14

def verify!
  @code = load_code(@path)
  result = Daigaku::Test.new(@unit_path).run(@code)
  self.store_state = result.passed?
  result
end