Class: Workout

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, comments = nil, creation_date = Time.new.strftime("%Y-%m-%d")) ⇒ Workout

Returns a new instance of Workout.



8
9
10
11
12
13
14
15
# File 'lib/workout.rb', line 8

def initialize(id, comments=nil, creation_date=Time.new.strftime("%Y-%m-%d"))
    @id = id
    @comments = comments
    @creation_date = creation_date
    @@all << self
    @exercises = []
    @workout_hash = self.hash_workout
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



2
3
4
# File 'lib/workout.rb', line 2

def comments
  @comments
end

#creation_dateObject

Returns the value of attribute creation_date.



2
3
4
# File 'lib/workout.rb', line 2

def creation_date
  @creation_date
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/workout.rb', line 2

def id
  @id
end

#workout_hashObject

Returns the value of attribute workout_hash.



2
3
4
# File 'lib/workout.rb', line 2

def workout_hash
  @workout_hash
end

Class Method Details

.allObject



22
23
24
# File 'lib/workout.rb', line 22

def self.all
    @@all
end

Instance Method Details

#add_selected_to_current_workout(exr) ⇒ Object



26
27
28
# File 'lib/workout.rb', line 26

def add_selected_to_current_workout(exr)
    exr.workout = self
end

#hash_workoutObject



17
18
19
20
# File 'lib/workout.rb', line 17

def hash_workout
    workout_hash = Hash.new
    workout_hash = {:id => id, :comments => comments, :creation_date => creation_date}
end

#session_exercisesObject



30
31
32
# File 'lib/workout.rb', line 30

def session_exercises
    @exercises = Exercise.all.select { |exr| exr.workout == self }
end

#set_exercise_arrayObject



34
35
36
37
38
39
# File 'lib/workout.rb', line 34

def set_exercise_array
    exercises = self.session_exercises
    match = self.session_exercises.find { |exr| exr.muscle == "Abs" }
    match_index = self.session_exercises.index(match)
    exercises = exercises.insert(-1,exercises.delete_at(match_index))
end