1 # == Schema Information
2 # Schema version: 20100224042103
6 # id :integer not null, primary key
7 # unit_id :integer not null
8 # problem_group_problem_id :integer
9 # level :integer default(0), not null
10 # amount :integer default(1), not null
11 # options :text not null
12 # lock_version :integer default(0), not null
13 # created_at :datetime
14 # updated_at :datetime
17 class Problem < ActiveRecord::Base
21 has_many :learning_results
22 has_many :problem_groups_problems, :class_name => 'ProblemGroupsProblems', :dependent => :destroy
23 has_many :problem_groups, :through => :problem_groups_problems
25 validates_presence_of :unit_id
27 validates_presence_of :level
28 validates_inclusion_of :level, :in => 0..100
30 validates_presence_of :amount
31 validates_inclusion_of :amount, :in => 1..100
33 validates_presence_of :options
36 # TODO remove this method
42 o = ActiveSupport::JSON.decode(options).symbolize_keys
43 o.each{|k, v| v.symbolize_keys! if Hash === v }
44 unit.generator(amount).generate(o).map{|v|
46 when String then Mint::Builder.build(v)