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.



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

def initialize
  @@all << self
end

Instance Attribute Details

#active_trackObject

Returns the value of attribute active_track.



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

def active_track
  @active_track
end

#completionObject

Returns the value of attribute completion.



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

def completion
  @completion
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#github_usernameObject

Returns the value of attribute github_username.



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

def github_username
  @github_username
end

#last_nameObject

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

Class Method Details

.allObject



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

def self.all
  @@all 
end

.attributes_from_data(data) ⇒ Object



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

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

.build_attributes(headers) ⇒ Object



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

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

.generate_from_data(data) ⇒ Object



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

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



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

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

#progressObject



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

def progress
  self.completion
end