Class: LearnTogether::GroupMaker
- Inherits:
-
Object
- Object
- LearnTogether::GroupMaker
- Defined in:
- lib/learn_together.rb
Constant Summary collapse
- VALID_ARGS =
{ valid_keys: ["groups_of", "collection", "sort_type", "number_of_groups"], sort_type: ["random", "progress"] }
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #has_valid_keys? ⇒ Boolean
- #has_valid_values? ⇒ Boolean
- #run(options) ⇒ Object
- #validate_args ⇒ Object
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/learn_together.rb', line 13 def @options end |
Instance Method Details
#has_valid_keys? ⇒ Boolean
27 28 29 |
# File 'lib/learn_together.rb', line 27 def has_valid_keys? .keys.all? {|key| VALID_ARGS[:valid_keys].include?(key)} end |
#has_valid_values? ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/learn_together.rb', line 31 def has_valid_values? if ["sort_type"] if VALID_ARGS[:sort_type].include?(["sort_type"]) true else false end else true end end |
#run(options) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/learn_together.rb', line 15 def run() @options = ActiveSupport::HashWithIndifferentAccess.new() validate_args students = Student.new([:collection]).generate_batch_students generator = Generator.new(students: students, groups_of: [:groups_of], number_of_groups: [:number_of_groups], sort_type: [:sort_type]) generator.make_groups end |
#validate_args ⇒ Object
23 24 25 |
# File 'lib/learn_together.rb', line 23 def validate_args (has_valid_keys? && has_valid_values?) ? true : (raise GroupMakerArgError.new) end |