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



115
116
117
# File 'lib/work_together.rb', line 115

def initialize
  @@all << self
end

Instance Attribute Details

#active_trackObject

Returns the value of attribute active_track.



113
114
115
# File 'lib/work_together.rb', line 113

def active_track
  @active_track
end

#completionObject

Returns the value of attribute completion.



113
114
115
# File 'lib/work_together.rb', line 113

def completion
  @completion
end

#emailObject

Returns the value of attribute email.



113
114
115
# File 'lib/work_together.rb', line 113

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



113
114
115
# File 'lib/work_together.rb', line 113

def first_name
  @first_name
end

#github_usernameObject

Returns the value of attribute github_username.



113
114
115
# File 'lib/work_together.rb', line 113

def github_username
  @github_username
end

#last_nameObject

Returns the value of attribute last_name.



113
114
115
# File 'lib/work_together.rb', line 113

def last_name
  @last_name
end

Class Method Details

.allObject



119
120
121
# File 'lib/work_together.rb', line 119

def self.all
  @@all 
end

.attributes_from_data(data) ⇒ Object



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

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

.build_attributes(headers) ⇒ Object



123
124
125
126
127
# File 'lib/work_together.rb', line 123

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

.generate_from_data(data) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/work_together.rb', line 142

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



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

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

#progressObject



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

def progress
  self.completion
end