Class: Series
- Inherits:
-
Object
- Object
- Series
- Defined in:
- lib/series.rb
Overview
This class represents a series in power training session.
Instance Method Summary collapse
-
#initialize(name) ⇒ Series
constructor
Initialization method for the
Seriesclass. -
#intensity(intensity) ⇒ Object
Adding an intensity in the range [1, 10] to the series.
-
#repetitions(repetitions) ⇒ Object
Adding a number of repetitions to the object.
-
#to_hash ⇒ Object
Converting a session to a JSON-ized string.
-
#to_s ⇒ Object
Converting a speed session to a string.
Constructor Details
#initialize(name) ⇒ Series
Initialization method for the Series class. Params:
name-
the name of the series
10 11 12 13 14 |
# File 'lib/series.rb', line 10 def initialize(name) @name = name @intensity = 0 @repetitions = 0 end |
Instance Method Details
#intensity(intensity) ⇒ Object
Adding an intensity in the range [1, 10] to the series. Params:
intensity-
intensity level
20 21 22 23 24 25 26 27 |
# File 'lib/series.rb', line 20 def intensity(intensity) intensity_str = intensity.to_s intensity_int = intensity.to_s.to_i raise 'The given intensity level is not an integer.' if intensity_str != intensity_str.to_i.to_s raise 'The intensity level should be between 1 and 10.' if intensity_int < 1 || intensity_int > 10 @intensity = intensity_int end |
#repetitions(repetitions) ⇒ Object
Adding a number of repetitions to the object. Params:
repetitions-
number of repetitions inside of a series
33 34 35 36 37 38 39 40 |
# File 'lib/series.rb', line 33 def repetitions(repetitions) repetitions_str = repetitions.to_s repetitions_int = repetitions.to_s.to_i raise 'The given number of repetitions is not an integer.' if repetitions_str != repetitions_str.to_i.to_s raise 'The minimum number of repetitions is 1.' if repetitions_int < 1 @repetitions = repetitions_int end |
#to_hash ⇒ Object
Converting a session to a JSON-ized string.
50 51 52 53 54 55 56 |
# File 'lib/series.rb', line 50 def to_hash { name: @name, intensity: @intensity, repetitions: @repetitions } end |
#to_s ⇒ Object
Converting a speed session to a string.
44 45 46 |
# File 'lib/series.rb', line 44 def to_s @name end |