Class: Power
- Inherits:
-
Object
- Object
- Power
- Defined in:
- lib/power.rb
Overview
This class represents a power training session.
Instance Method Summary collapse
-
#initialize(name) ⇒ Power
constructor
Initialization method for the
Power
class. -
#series(name, &block) ⇒ Object
Building a new series from the domain specific language.
-
#sport(type) ⇒ Object
Adding a sport type 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) ⇒ Power
Initialization method for the Power
class. Params:
name
-
the name of the power session
13 14 15 16 17 |
# File 'lib/power.rb', line 13 def initialize(name) @name = name @series = [] @sport = '' end |
Instance Method Details
#series(name, &block) ⇒ Object
Building a new series from the domain specific language. Params:
name
-
the name of the series
block
-
power session data
24 25 26 27 28 |
# File 'lib/power.rb', line 24 def series(name, &block) series_data = Series.new(name) series_data.instance_eval(&block) @series << series_data end |
#sport(type) ⇒ Object
Adding a sport type to the object. Params:
type
-
the type of the sport
34 35 36 37 38 |
# File 'lib/power.rb', line 34 def sport(type) raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type @sport = type end |
#to_hash ⇒ Object
Converting a session to a JSON-ized string.
48 49 50 51 52 53 54 |
# File 'lib/power.rb', line 48 def to_hash { name: @name, sport: @sport, series: @series.collect(&:to_hash) } end |
#to_s ⇒ Object
Converting a speed session to a string.
42 43 44 |
# File 'lib/power.rb', line 42 def to_s @name end |