Class: LearnParty::GroupMaker

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

Constant Summary collapse

VALID_ARGS =
{
valid_keys: ["groups_of", "collection", "sort_type", "number_of_groups"],
sort_type: ["random", "progress"]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/learn_party.rb', line 13

def options
  @options
end

Instance Method Details

#has_valid_keys?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/learn_party.rb', line 27

def has_valid_keys?
  options.keys.all? {|key| VALID_ARGS[:valid_keys].include?(key)}
end

#has_valid_values?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/learn_party.rb', line 31

def has_valid_values?
  if options["sort_type"]
    if VALID_ARGS[:sort_type].include?(options["sort_type"])
      true
    else
      false
    end
  else
    true
  end
end

#run(options) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/learn_party.rb', line 15

def run(options)
  @options = ActiveSupport::HashWithIndifferentAccess.new(options)
  validate_args
  students = Student.new(options[:collection]).generate_batch_students
  generator = Generator.new(students: students, groups_of: options[:groups_of], number_of_groups: options[:number_of_groups], sort_type: options[:sort_type])
  generator.make_groups
end

#validate_argsObject



23
24
25
# File 'lib/learn_party.rb', line 23

def validate_args
  (has_valid_keys? && has_valid_values?) ? true : (raise GroupMakerArgError.new)
end