Class: Daigaku::Solution

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

Constant Summary collapse

FILE_SUFFIX =
'_solution.rb'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

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



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