Class: WorkTogether::Student

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStudent

Returns a new instance of Student.



132
133
134
# File 'lib/work_together.rb', line 132

def initialize
  @@all << self
end

Instance Attribute Details

#active_trackObject

Returns the value of attribute active_track.



130
131
132
# File 'lib/work_together.rb', line 130

def active_track
  @active_track
end

#completionObject

Returns the value of attribute completion.



130
131
132
# File 'lib/work_together.rb', line 130

def completion
  @completion
end

#emailObject

Returns the value of attribute email.



130
131
132
# File 'lib/work_together.rb', line 130

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



130
131
132
# File 'lib/work_together.rb', line 130

def first_name
  @first_name
end

#github_usernameObject

Returns the value of attribute github_username.



130
131
132
# File 'lib/work_together.rb', line 130

def github_username
  @github_username
end

#last_nameObject

Returns the value of attribute last_name.



130
131
132
# File 'lib/work_together.rb', line 130

def last_name
  @last_name
end

Class Method Details

.allObject



136
137
138
# File 'lib/work_together.rb', line 136

def self.all
  @@all 
end

.attributes_from_data(data) ⇒ Object



154
155
156
157
# File 'lib/work_together.rb', line 154

def self.attributes_from_data(data)
  attributes = data.first.to_hash.keys
  self.build_attributes(attributes)
end

.build_attributes(headers) ⇒ Object



140
141
142
143
144
# File 'lib/work_together.rb', line 140

def self.build_attributes(headers)
  headers.each do |header| 
    attr_accessor header.to_sym
  end
end

.generate_from_data(data) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/work_together.rb', line 159

def self.generate_from_data(data)
  attributes_from_data(data)
  data.each do |student_hash|
    student_hash.delete_if {|attribute, value| !Student.instance_methods.include?(attribute.to_sym)}
    self.new.tap do |student|
      student_hash.each do |attribute, value|
        student.public_send("#{attribute}=", value)
      end
    end
  end
end

Instance Method Details

#nameObject



146
147
148
# File 'lib/work_together.rb', line 146

def name
  "#{first_name} #{last_name}"
end

#progressObject



150
151
152
# File 'lib/work_together.rb', line 150

def progress
  self.completion
end