Class: LearnParty::Student

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ Student

Returns a new instance of Student.



53
54
55
# File 'lib/learn_party.rb', line 53

def initialize(collection)
  @collection = collection
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



51
52
53
# File 'lib/learn_party.rb', line 51

def collection
  @collection
end

Instance Method Details

#generate_batch_studentsObject



57
58
59
60
61
62
63
64
65
# File 'lib/learn_party.rb', line 57

def generate_batch_students
  if student_hash_type
    return collection.collect {|s| OpenStruct.new(s)}
  elsif student_instance_object_type
    return collection
  else
    raise StudentTypeError.new
  end
end

#student_hash_typeObject



67
68
69
# File 'lib/learn_party.rb', line 67

def student_hash_type
  collection.first.is_a?(Hash) && (collection.first.keys.include?("completed_lesson_count_for_active_track" || :completed_lesson_count_for_active_track))
end

#student_instance_object_typeObject



71
72
73
# File 'lib/learn_party.rb', line 71

def student_instance_object_type
  collection.first.respond_to?(:completed_lesson_count_for_active_track)
end