ast-tdl 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ebd58255ecf60ba24423a07251499fb473c2751363795b9058a99a015a5efae
4
- data.tar.gz: f157c466e4feb81fa9ff3f50d65087f236c73083e854ed579f8a616888fa4c0b
3
+ metadata.gz: f80f5ce52b90eddc0e2a1d7500a9cb72266cbb9942b48abe51452fc0e5772ed7
4
+ data.tar.gz: '019b6ee3ace2a1bf5075f4eda8bbde0e84fd01ad76edef4c8e449d91feefb6a7'
5
5
  SHA512:
6
- metadata.gz: '08a3b71fd3c412338bb93d6c9aef954bd7a357e8e6dc190560b977ad7b7a0f9b4f4252ced3c5aedaf152ae3853023efc85b4663a2d60aaee24e264eab14ef6fa'
7
- data.tar.gz: 6a4a15557718d2abf418b9076f8075344d16308a2478e56a0c90deed727896ade8b539f69a1de270e77e3b0f8a75fb57433860747a5064d901e4479d4a53b341
6
+ metadata.gz: 6c63722d51efd64fe0ec516b3861668ea5a9ba96dbb0b4449822ad7b3b0db96922d73addcc6a69fb28de517a608e13f05ccf57a27f15483f87263a97350feb0d
7
+ data.tar.gz: 8696fbc00936ba6fe0a533aa5f70e5745d96ba7b9f189267a7d3b40763262477348fede00c69b5de8a214db99850bce9fcb5b64d12ef339df35a4c0b686f094b
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Iztok Fister Jr.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,33 +1,61 @@
1
1
  # Training Description Language (TDL) for Artificial Sport Trainer (AST)
2
2
 
3
- AST-DSL is a very small domain-specific language
3
+ ## Motivation
4
+ ast-dsl is intended to be a small DSL for practical definition and description of sports training that can be automatically or manually defined and used in conjunction with Artificial Sport Trainer.
4
5
 
5
- ## Objective
6
+ ## Feature diagram
7
+ ![scheme](https://user-images.githubusercontent.com/73126820/175337865-77344476-b7c8-45d4-bda2-0aca82aebefd.png)
6
8
 
7
9
  ## Installation
8
-
9
10
  $ gem install ast-tdl
10
11
 
11
12
  ## Language description
13
+ Training Description Language (TDL) is implemented in Ruby. Currently, the description of sports training sessions and intervals is now supported. Those contain various data, such as duration, average heart rate, sport type, and many more.
12
14
 
13
15
  ## Examples
16
+ ```ruby
17
+ EasyTraining = Ast.build :Monday do
18
+ session("Short swimming session today") {
19
+ sport :"swim"
20
+ info :"Very easy training"
21
+ average_heart_rate :"130"
22
+ total_duration :"30"
23
+ }
24
+
25
+ session("Bike ride") {
26
+ sport :"bike"
27
+ info :"Endurance ride with intervals"
28
+ average_heart_rate :"140"
29
+ total_duration :"250"
30
+ }
31
+
32
+ interval("Number 1") {
33
+ sport :"swim"
34
+ info :"Moderate"
35
+ average_heart_rate :"160"
36
+ total_duration :"5"
37
+ average_heart_rate_rest :"90"
38
+ total_duration_rest :"2"
39
+ }
40
+ end
41
+ ```
14
42
 
15
43
  ### Session
16
-
17
44
  ```ruby
18
45
  session("Short swimming session today") {
19
- sport :"swim"
20
- info :"Very easy training"
21
- avhr :"130"
22
- td :"30"
46
+ sport :"swim"
47
+ info :"Very easy training"
48
+ average_heart_rate :"130"
49
+ total_duration :"30"
23
50
  }
24
51
  ```
25
- ## License
26
52
 
53
+ ## License
27
54
  This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
28
55
 
29
56
  ## Disclaimer
30
-
31
57
  This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!
32
58
 
59
+ ## References
33
60
 
61
+ Fister Jr, I., Fister, I., Iglesias, A., Galvez, A., Deb, S., & Fister, D. (2021). On deploying the Artificial Sport Trainer into practice. arXiv preprint [arXiv:2109.13334](https://arxiv.org/abs/2109.13334).
data/lib/ast-tdl.rb CHANGED
@@ -1 +1,3 @@
1
- require_relative "./ast"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './ast'
data/lib/ast.rb CHANGED
@@ -1,86 +1,84 @@
1
- require "json"
2
-
3
- require_relative "classes"
4
- require_relative "interval"
5
- require_relative "session"
1
+ # frozen_string_literal: true
6
2
 
3
+ require 'json'
4
+ require_relative 'interval'
5
+ require_relative 'session'
7
6
 
8
7
  ##
9
8
  # This module is intended to be used for building trainings
10
9
  # from the domain specific language AST-TDL.
11
10
  module Ast
12
- ##
13
- # Building a new training from the domain specific language.
14
- # Params:
15
- # +name+:: the name of the training
16
- # +block+:: training data
17
- def self.build(name, &block)
18
- training = Training.new(name)
19
- training.instance_eval(&block)
20
- return training
21
- end
22
-
11
+ ##
12
+ # Building a new training from the domain specific language.
13
+ # Params:
14
+ # +name+:: the name of the training
15
+ # +block+:: training data
16
+ def self.build(name, &block)
17
+ training = Training.new(name)
18
+ training.instance_eval(&block)
19
+ training
20
+ end
23
21
 
24
- ##
25
- # This class represents a training with a name, sessions and intervals.
26
- class Training
27
- ##
28
- # Initialization method for the +Training+ class.
29
- # Params:
30
- # +name+:: the name of the training
31
- def initialize(name)
32
- @name = name
33
- @session = []
34
- @interval = []
35
- end
22
+ ##
23
+ # This class represents a training with a name, sessions and intervals.
24
+ class Training
25
+ ##
26
+ # Initialization method for the +Training+ class.
27
+ # Params:
28
+ # +name+:: the name of the training
29
+ def initialize(name)
30
+ @name = name
31
+ @session = []
32
+ @interval = []
33
+ end
36
34
 
37
- ##
38
- # Building a new session from the domain specific language.
39
- # Params:
40
- # +name+:: the name of the session
41
- # +block+:: session data
42
- def session(name, &block)
43
- training_type = Session.new(name)
44
- training_type.instance_eval(&block)
45
- @session << training_type
46
- end
35
+ ##
36
+ # Building a new session from the domain specific language.
37
+ # Params:
38
+ # +name+:: the name of the session
39
+ # +block+:: session data
40
+ def session(name, &block)
41
+ training_type = Session.new(name)
42
+ training_type.instance_eval(&block)
43
+ @session << training_type
44
+ end
47
45
 
48
- ##
49
- # Building a new interval from the domain specific language.
50
- # Params:
51
- # +name+:: the name of the interval
52
- # +block+:: interval data
53
- def interval(name, &block)
54
- interval_data = Interval.new(name)
55
- interval_data.instance_eval(&block)
56
- @interval << interval_data
57
- end
46
+ ##
47
+ # Building a new interval from the domain specific language.
48
+ # Params:
49
+ # +name+:: the name of the interval
50
+ # +block+:: interval data
51
+ def interval(name, &block)
52
+ interval_data = Interval.new(name)
53
+ interval_data.instance_eval(&block)
54
+ @interval << interval_data
55
+ end
58
56
 
59
- ##
60
- # Converting a training to a string.
61
- def to_s
62
- str = "#{@name} #{@session[0]}"
63
- end
57
+ ##
58
+ # Converting a training to a string.
59
+ def to_s
60
+ "#{@name} #{@session[0]}"
61
+ end
64
62
 
65
- ##
66
- # Converting a training to a JSON-ized string.
67
- def json
68
- training_json = {
69
- name: @name,
70
- session: @session.collect { |s| s.to_hash },
71
- interval: @interval.collect { |i| i.to_hash },
72
- }
73
- training_json.to_json
74
- end
63
+ ##
64
+ # Converting a training to a JSON-ized string.
65
+ def json
66
+ training_json = {
67
+ name: @name,
68
+ session: @session.collect(&:to_hash),
69
+ interval: @interval.collect(&:to_hash)
70
+ }
71
+ JSON.pretty_generate(training_json)
72
+ end
75
73
 
76
- ##
77
- # Saving a training to a JSON file.
78
- # Params:
79
- # +filename+:: the desired name of the file
80
- def save_to_file(filename)
81
- f = File.open(filename, "w")
82
- f.puts(json)
83
- f.close
84
- end
85
- end
74
+ ##
75
+ # Saving a training to a JSON file.
76
+ # Params:
77
+ # +filename+:: the desired name of the file
78
+ def save_to_file(filename)
79
+ f = File.open(filename, 'w')
80
+ f.puts(json)
81
+ f.close
82
+ end
83
+ end
86
84
  end
data/lib/interval.rb CHANGED
@@ -1,85 +1,100 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ##
2
4
  # This class represents an interval.
3
5
  class Interval
4
- ##
5
- # Initialization method for the +Interval+ class.
6
- # Params:
7
- # +name+:: the name of the interval
8
- def initialize(name)
9
- @name = []
10
- @sport = []
11
- @info = []
12
- @average_heart_rate = []
13
- @total_duration = []
14
- @average_heart_rate_rest = []
15
- @total_duration_rest = []
16
- end
6
+ ##
7
+ # Initialization method for the +Interval+ class.
8
+ # Params:
9
+ # +name+:: the name of the interval
10
+ def initialize(name)
11
+ @name = name
12
+ @sport = ''
13
+ @info = ''
14
+ @speed_duration = 0
15
+ @recovery_duration = 0
16
+ @speed_heart_rate = 0
17
+ @recovery_heart_rate = 0
18
+ @repetitions = 0
19
+ end
20
+
21
+ ##
22
+ # Adding a sport to the object.
23
+ # Params:
24
+ # +type+:: the type of the sport
25
+ def sport(type)
26
+ @sport = type
27
+ end
28
+
29
+ ##
30
+ # Adding an info message to the object.
31
+ # Params:
32
+ # +message+:: the info message
33
+ def info(message)
34
+ @info = message
35
+ end
36
+
37
+ ##
38
+ # Adding a speed duration of an interval to the object.
39
+ # Params:
40
+ # +speed_duration+:: the duration of the speed segment in minutes
41
+ def speed_duration(speed_duration)
42
+ @speed_duration = speed_duration.to_s.to_i
43
+ end
44
+
45
+ ##
46
+ # Adding a recovery duration of an interval to the object.
47
+ # Params:
48
+ # +recovery_duration+:: the duration of the recovery segment in minutes
49
+ def recovery_duration(recovery_duration)
50
+ @recovery_duration = recovery_duration.to_s.to_i
51
+ end
52
+
53
+ ##
54
+ # Adding a speed heart rate of an interval to the object.
55
+ # Params:
56
+ # +speed_heart_rate+:: the average speed heart rate in bpm
57
+ def speed_heart_rate(speed_heart_rate)
58
+ @speed_heart_rate = speed_heart_rate.to_s.to_i
59
+ end
17
60
 
18
- ##
19
- # Building a new Sport object.
20
- # Params:
21
- # +type+:: the type of the sport
22
- def sport(type)
23
- @sport << Sport.new(type)
24
- end
61
+ ##
62
+ # Adding a recovery heart rate of an interval to the object.
63
+ # Params:
64
+ # +recovery_heart_rate+:: the average speed heart rate in bpm
65
+ def recovery_heart_rate(recovery_heart_rate)
66
+ @recovery_heart_rate = recovery_heart_rate.to_s.to_i
67
+ end
25
68
 
26
- ##
27
- # Building a new Info object.
28
- # Params:
29
- # +message+:: the info message
30
- def info(message)
31
- @info << Info.new(message)
32
- end
69
+ ##
70
+ # Adding a number of repetitions to the object.
71
+ # Params:
72
+ # +repetitions+:: number of interval repetitions
73
+ def repetitions(repetitions)
74
+ @repetitions = repetitions.to_s.to_i
75
+ end
33
76
 
34
- ##
35
- # Building a new AverageHeartRate object.
36
- # Params:
37
- # +heart_rate+:: the average heart rate in bpm
38
- def average_heart_rate(heart_rate)
39
- @average_heart_rate << AverageHeartRate.new(heart_rate)
40
- end
77
+ ##
78
+ # Converting an interval to a string.
79
+ def to_s
80
+ "#{@sport} #{@info}"
81
+ end
41
82
 
42
- ##
43
- # Building a new TotalDuration object.
44
- # Params:
45
- # +duration+:: the duration in seconds
46
- def total_duration(duration)
47
- @total_duration << TotalDuration.new(duration)
48
- end
49
-
50
- ##
51
- # Building a new AverageHeartRateRest object.
52
- # Params:
53
- # +heart_rate_rest+:: the average rest heart rate in bpm
54
- def average_heart_rate_rest(heart_rate_rest)
55
- @average_heart_rate_rest << AverageHeartRateRest.new(heart_rate_rest)
56
- end
57
-
58
- ##
59
- # Building a new TotalDurationRest object.
60
- # Params:
61
- # +duration rest+:: the rest duration in seconds
62
- def total_duration_rest(duration_rest)
63
- @total_duration_rest << TotalDurationRest.new(duration_rest)
64
- end
65
-
66
- ##
67
- # Converting an interval to a string.
68
- def to_s
69
- str = "#{@sport[0].type} #{@info[0].message}"
70
- end
83
+ ##
84
+ # Converting an interval to a JSON-ized string.
85
+ def to_hash
86
+ hash = {
87
+ name: @name,
88
+ sport: @sport,
89
+ info: @info,
90
+ speed_duration: @speed_duration,
91
+ recovery_duration: @recovery_duration,
92
+ speed_heart_rate: @speed_heart_rate,
93
+ recovery_heart_rate: @recovery_heart_rate,
94
+ repetitions: @repetitions
95
+ }
71
96
 
72
- ##
73
- # Converting an interval to a JSON-ized string.
74
- def to_hash
75
- interval_json = {
76
- name: @name.collect { |x| x.to_hash },
77
- sport: @sport.collect { |x| x.to_hash },
78
- info: @info.collect { |x| x.to_hash },
79
- average_heart_rate: @average_heart_rate.collect { |x| x.to_hash },
80
- total_duration: @total_duration.collect { |x| x.to_hash },
81
- average_heart_rate_rest: @average_heart_rate_rest.collect { |x| x.to_hash },
82
- total_duration_rest: @total_duration_rest.collect { |x| x.to_hash },
83
- }
84
- end
85
- end
97
+ hash[:info] = @info if @info
98
+ hash
99
+ end
100
+ end
data/lib/session.rb CHANGED
@@ -1,65 +1,69 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ##
2
4
  # This class represents a session.
3
5
  class Session
4
- ##
5
- # Initialization method for the +Session+ class.
6
- # Params:
7
- # +name+:: the name of the session
8
- def initialize(name)
9
- @name = []
10
- @sport = []
11
- @info = []
12
- @average_heart_rate = []
13
- @total_duration = []
14
- end
6
+ ##
7
+ # Initialization method for the +Session+ class.
8
+ # Params:
9
+ # +name+:: the name of the session
10
+ def initialize(name)
11
+ @name = name
12
+ @sport = ''
13
+ @info = ''
14
+ @average_heart_rate = 0
15
+ @total_duration = 0
16
+ end
17
+
18
+ ##
19
+ # Adding a sport type to the object.
20
+ # Params:
21
+ # +type+:: the type of the sport
22
+ def sport(type)
23
+ @sport = type
24
+ end
15
25
 
16
- ##
17
- # Building a new Sport object.
18
- # Params:
19
- # +type+:: the type of the sport
20
- def sport(type)
21
- @sport << Sport.new(type)
22
- end
26
+ ##
27
+ # Adding a message to the object.
28
+ # Params:
29
+ # +message+:: the info message
30
+ def info(message)
31
+ @info = message
32
+ end
23
33
 
24
- ##
25
- # Building a new Info object.
26
- # Params:
27
- # +message+:: the info message
28
- def info(message)
29
- @info << Info.new(message)
30
- end
34
+ ##
35
+ # Adding an average heart rate to the object.
36
+ # Params:
37
+ # +heart_rate+:: the average heart rate in bpm
38
+ def average_heart_rate(heart_rate)
39
+ @average_heart_rate = heart_rate.to_s.to_i
40
+ end
31
41
 
32
- ##
33
- # Building a new AverageHeartRate object.
34
- # Params:
35
- # +heart_rate+:: the average heart rate in bpm
36
- def average_heart_rate(heart_rate)
37
- @average_heart_rate << AverageHeartRate.new(heart_rate)
38
- end
42
+ ##
43
+ # Adding a total duration to the object.
44
+ # Params:
45
+ # +duration+:: the duration in minutes
46
+ def total_duration(duration)
47
+ @total_duration = duration.to_s.to_i
48
+ end
39
49
 
40
- ##
41
- # Building a new TotalDuration object.
42
- # Params:
43
- # +duration+:: the duration in seconds
44
- def total_duration(duration)
45
- @total_duration << TotalDuration.new(duration)
46
- end
50
+ ##
51
+ # Converting a session to a string.
52
+ def to_s
53
+ "#{@sport} #{@info}"
54
+ end
47
55
 
48
- ##
49
- # Converting a session to a string.
50
- def to_s
51
- str = "#{@sport[0].type} #{@info[0].message}"
52
- end
56
+ ##
57
+ # Converting a session to a JSON-ized string.
58
+ def to_hash
59
+ hash = {
60
+ name: @name,
61
+ sport: @sport,
62
+ average_heart_rate: @average_heart_rate,
63
+ total_duration: @total_duration,
64
+ }
53
65
 
54
- ##
55
- # Converting a session to a JSON-ized string.
56
- def to_hash
57
- session_json = {
58
- name: @name.collect { |x| x.to_hash },
59
- sport: @sport.collect { |x| x.to_hash },
60
- info: @info.collect { |x| x.to_hash },
61
- average_heart_rate: @average_heart_rate.collect { |x| x.to_hash },
62
- total_duration: @total_duration.collect { |x| x.to_hash },
63
- }
64
- end
65
- end
66
+ hash[:info] = @info if @info != ''
67
+ hash
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ast-tdl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - firefly-cpp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-14 00:00:00.000000000 Z
12
+ date: 2022-07-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -19,18 +19,19 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - LICENSE
22
23
  - README.md
23
24
  - lib/ast-tdl.rb
24
25
  - lib/ast.rb
25
- - lib/classes.rb
26
26
  - lib/interval.rb
27
27
  - lib/session.rb
28
- homepage: https://github.com/firefly-cpp/AST-DSL
29
- licenses: []
28
+ homepage: https://github.com/firefly-cpp/ast-tdl
29
+ licenses:
30
+ - MIT
30
31
  metadata:
31
- homepage_uri: https://github.com/firefly-cpp/AST-DSL
32
- source_code_uri: https://github.com/firefly-cpp/AST-DSL
33
- changelog_uri: https://github.com/firefly-cpp/AST-DSL
32
+ homepage_uri: https://github.com/firefly-cpp/ast-tdl
33
+ source_code_uri: https://github.com/firefly-cpp/ast-tdl
34
+ changelog_uri: https://github.com/firefly-cpp/ast-tdl
34
35
  post_install_message:
35
36
  rdoc_options: []
36
37
  require_paths:
@@ -39,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
40
  requirements:
40
41
  - - ">="
41
42
  - !ruby/object:Gem::Version
42
- version: 2.4.0
43
+ version: 2.6.0
43
44
  required_rubygems_version: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - ">="
data/lib/classes.rb DELETED
@@ -1,156 +0,0 @@
1
- require "json"
2
-
3
-
4
- ##
5
- # This class represents a sport with a type.
6
- class Sport
7
- # The type of a sport.
8
- attr_reader :type
9
-
10
- ##
11
- # Initialization method for the +Sport+ class.
12
- # Params:
13
- # +type+:: the type of the sport
14
- def initialize(type)
15
- @type = type
16
- end
17
-
18
- ##
19
- # Converting +Sport+ class to a hash.
20
- def to_hash
21
- sport_json = {
22
- type: @type
23
- }
24
- end
25
- end
26
-
27
-
28
- ##
29
- # This class represents information with a message.
30
- class Info
31
- # The info message.
32
- attr_reader :message
33
-
34
- ##
35
- # Initialization method for the +Info+ class.
36
- # Params:
37
- # +message+:: the info message
38
- def initialize(message)
39
- @message = message
40
- end
41
-
42
- ##
43
- # Converting +Info+ class to a hash.
44
- def to_hash
45
- info_json = {
46
- message: @message
47
- }
48
- end
49
- end
50
-
51
-
52
- ##
53
- # This class represents an average heart rate.
54
- class AverageHeartRate
55
- # An average heart rate.
56
- attr_reader :heart_rate
57
-
58
- ##
59
- # Initialization method for the +AverageHeartRate+ class.
60
- # Params:
61
- # +heart_rate+:: the average heart rate
62
- def initialize(heart_rate)
63
- heart_rate = heart_rate.to_s.to_i
64
- if heart_rate > 220
65
- raise ArgumentError.new("Maximum heart rate is 220.")
66
- end
67
-
68
- @heart_rate = heart_rate
69
- end
70
-
71
- ##
72
- # Converting +AverageHeartRate+ class to a hash.
73
- def to_hash
74
- info_json = {
75
- average_hr: @heart_rate
76
- }
77
- end
78
- end
79
-
80
-
81
- ##
82
- # This class represents a total duration of a session or an interval.
83
- class TotalDuration
84
- # The total duration in seconds.
85
- attr_reader :duration
86
-
87
- ##
88
- # Initialization method for the +TotalDuration+ class.
89
- # Params:
90
- # +duration+:: the total duration
91
- def initialize(duration)
92
- @duration = duration
93
- end
94
-
95
- ##
96
- # Converting +TotalDuration+ class to a hash.
97
- def to_hash
98
- td_json = {
99
- duration: @duration
100
- }
101
- end
102
- end
103
-
104
-
105
- ##
106
- # This class represents an average heart rate in the resting period.
107
- class AverageHeartRateRest
108
- # The average rest heart rate.
109
- attr_reader :average_heart_rate_rest
110
-
111
- ##
112
- # Initialization method for the +AverageHeartRateRest+ class.
113
- # Params:
114
- # +average_heart_rate_rest+:: the average heart rate
115
- def initialize(average_heart_rate_rest)
116
- average_heart_rate_rest = average_heart_rate_rest.to_s.to_i
117
- if average_heart_rate_rest > 220
118
- raise ArgumentError.new("Maximum heart rate is 220.")
119
- end
120
-
121
- @average_heart_rate_rest = average_heart_rate_rest
122
- end
123
-
124
- ##
125
- # Converting +AverageHeartRateRest+ class to a hash.
126
- def to_hash
127
- average_heart_rate_json = {
128
- average_heart_rate_rest: @average_heart_rate_rest
129
- }
130
- end
131
- end
132
-
133
-
134
- ##
135
- # This class represents a total duration of a session or an
136
- # interval in the resting period.
137
- class TotalDurationRest
138
- # The total duration in seconds.
139
- attr_reader :total_duration_rest
140
-
141
- ##
142
- # Initialization method for the +TotalDurationRest+ class.
143
- # Params:
144
- # +total_duration_rest+:: the total rest duration
145
- def initialize(total_duration_rest)
146
- @total_duration_rest = total_duration_rest
147
- end
148
-
149
- ##
150
- # Converting +TotalDurationRest+ class to a hash.
151
- def to_hash
152
- total_duration_rest_json = {
153
- total_duration_rest: @total_duration_rest
154
- }
155
- end
156
- end