Class: Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/data/problem.rb

Constant Summary collapse

@@id =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProblem

Returns a new instance of Problem.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asker/data/problem.rb', line 17

def initialize
  @@id += 1
  @id = @@id
  @lang = LangFactory.instance.get("en")
  @context = nil
  @process = false
  @filename = "?"
  @varnames = []
  @cases = []
  @descs = []
  @asks = []
  @questions = []
  @stats = { answer: 0, steps: 0}
end

Instance Attribute Details

#asksObject

Returns the value of attribute asks.



12
13
14
# File 'lib/asker/data/problem.rb', line 12

def asks
  @asks
end

#casesObject

Returns the value of attribute cases.



10
11
12
# File 'lib/asker/data/problem.rb', line 10

def cases
  @cases
end

#contextObject

Returns the value of attribute context.



6
7
8
# File 'lib/asker/data/problem.rb', line 6

def context
  @context
end

#descsObject

Returns the value of attribute descs.



11
12
13
# File 'lib/asker/data/problem.rb', line 11

def descs
  @descs
end

#filenameObject

Returns the value of attribute filename.



8
9
10
# File 'lib/asker/data/problem.rb', line 8

def filename
  @filename
end

#langObject

Returns the value of attribute lang.



5
6
7
# File 'lib/asker/data/problem.rb', line 5

def lang
  @lang
end

#processObject

Returns the value of attribute process.



7
8
9
# File 'lib/asker/data/problem.rb', line 7

def process
  @process
end

#questionsObject

Returns the value of attribute questions.



13
14
15
# File 'lib/asker/data/problem.rb', line 13

def questions
  @questions
end

#statsObject

Returns the value of attribute stats.



14
15
16
# File 'lib/asker/data/problem.rb', line 14

def stats
  @stats
end

#varnamesObject

Returns the value of attribute varnames.



9
10
11
# File 'lib/asker/data/problem.rb', line 9

def varnames
  @varnames
end

Class Method Details

.from(values) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/asker/data/problem.rb', line 32

def self.from(values)
  problem = Problem.new
  fields = %i[filename varnames cases descs asks]
  fields.each do |fieldname|
    methodname = "#{fieldname}=".to_sym
    problem.send(methodname, values[fieldname])
  end
  problem.validate
  problem
end

Instance Method Details

#descObject



43
44
45
# File 'lib/asker/data/problem.rb', line 43

def desc
  @descs.first
end

#nameObject



51
52
53
54
# File 'lib/asker/data/problem.rb', line 51

def name
  firstword = @descs[0]&.strip&.split(" ")&.first&.downcase || "problem"
  "#{firstword}#{@id}"
end

#process?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/asker/data/problem.rb', line 47

def process?
  @process
end

#validateObject



56
57
58
59
60
61
# File 'lib/asker/data/problem.rb', line 56

def validate
  validate_varnames
  validate_cases
  validate_asks
  validate_descs
end