Class: Problem
- Inherits:
-
Object
- Object
- Problem
- Defined in:
- lib/asker/data/problem.rb
Constant Summary collapse
- @@id =
0
Instance Attribute Summary collapse
-
#asks ⇒ Object
Returns the value of attribute asks.
-
#cases ⇒ Object
Returns the value of attribute cases.
-
#context ⇒ Object
Returns the value of attribute context.
-
#descs ⇒ Object
Returns the value of attribute descs.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#process ⇒ Object
Returns the value of attribute process.
-
#questions ⇒ Object
Returns the value of attribute questions.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#varnames ⇒ Object
Returns the value of attribute varnames.
Class Method Summary collapse
Instance Method Summary collapse
- #desc ⇒ Object
-
#initialize ⇒ Problem
constructor
A new instance of Problem.
- #name ⇒ Object
- #process? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize ⇒ Problem
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
#asks ⇒ Object
Returns the value of attribute asks.
12 13 14 |
# File 'lib/asker/data/problem.rb', line 12 def asks @asks end |
#cases ⇒ Object
Returns the value of attribute cases.
10 11 12 |
# File 'lib/asker/data/problem.rb', line 10 def cases @cases end |
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/asker/data/problem.rb', line 6 def context @context end |
#descs ⇒ Object
Returns the value of attribute descs.
11 12 13 |
# File 'lib/asker/data/problem.rb', line 11 def descs @descs end |
#filename ⇒ Object
Returns the value of attribute filename.
8 9 10 |
# File 'lib/asker/data/problem.rb', line 8 def filename @filename end |
#lang ⇒ Object
Returns the value of attribute lang.
5 6 7 |
# File 'lib/asker/data/problem.rb', line 5 def lang @lang end |
#process ⇒ Object
Returns the value of attribute process.
7 8 9 |
# File 'lib/asker/data/problem.rb', line 7 def process @process end |
#questions ⇒ Object
Returns the value of attribute questions.
13 14 15 |
# File 'lib/asker/data/problem.rb', line 13 def questions @questions end |
#stats ⇒ Object
Returns the value of attribute stats.
14 15 16 |
# File 'lib/asker/data/problem.rb', line 14 def stats @stats end |
#varnames ⇒ Object
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
#desc ⇒ Object
43 44 45 |
# File 'lib/asker/data/problem.rb', line 43 def desc @descs.first end |
#name ⇒ Object
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
47 48 49 |
# File 'lib/asker/data/problem.rb', line 47 def process? @process end |
#validate ⇒ Object
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 |