ast-tdl 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ast.rb +1 -2
  3. data/lib/interval.rb +50 -37
  4. data/lib/session.rb +24 -22
  5. metadata +2 -3
  6. data/lib/classes.rb +0 -148
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 757763f7548180daaeaf4e4d427a9837584d0f3b68ef8b08fc2cefffab8b293e
4
- data.tar.gz: 4518d44a21c598c06872b1b5c60d13cd62816fd192e550c80a7e45f9617c4306
3
+ metadata.gz: f80f5ce52b90eddc0e2a1d7500a9cb72266cbb9942b48abe51452fc0e5772ed7
4
+ data.tar.gz: '019b6ee3ace2a1bf5075f4eda8bbde0e84fd01ad76edef4c8e449d91feefb6a7'
5
5
  SHA512:
6
- metadata.gz: cf4a6d62f36951fcf352b6c93d31d4ba2a170169b1a82e7beb493b3283c7df5f1eecef2f62bdd94a18f86437e647665a8d2f5c5af357e82925b1ea199a10d642
7
- data.tar.gz: d594576289625b607ebb359fbbe5e22623fafd0f9dcf904d33cc088b479dbfdba1c6b9c022c65e2534891cd7ae7295d770ee93d3bea322464d65f243dea30b3b
6
+ metadata.gz: 6c63722d51efd64fe0ec516b3861668ea5a9ba96dbb0b4449822ad7b3b0db96922d73addcc6a69fb28de517a608e13f05ccf57a27f15483f87263a97350feb0d
7
+ data.tar.gz: 8696fbc00936ba6fe0a533aa5f70e5745d96ba7b9f189267a7d3b40763262477348fede00c69b5de8a214db99850bce9fcb5b64d12ef339df35a4c0b686f094b
data/lib/ast.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require_relative 'classes'
5
4
  require_relative 'interval'
6
5
  require_relative 'session'
7
6
 
@@ -69,7 +68,7 @@ module Ast
69
68
  session: @session.collect(&:to_hash),
70
69
  interval: @interval.collect(&:to_hash)
71
70
  }
72
- training_json.to_json
71
+ JSON.pretty_generate(training_json)
73
72
  end
74
73
 
75
74
  ##
data/lib/interval.rb CHANGED
@@ -7,81 +7,94 @@ class Interval
7
7
  # Initialization method for the +Interval+ class.
8
8
  # Params:
9
9
  # +name+:: the name of the interval
10
- def initialize(_name)
11
- @name = []
12
- @sport = []
13
- @info = []
14
- @average_heart_rate = []
15
- @total_duration = []
16
- @average_heart_rate_rest = []
17
- @total_duration_rest = []
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
18
19
  end
19
20
 
20
21
  ##
21
- # Building a new Sport object.
22
+ # Adding a sport to the object.
22
23
  # Params:
23
24
  # +type+:: the type of the sport
24
25
  def sport(type)
25
- @sport << Sport.new(type)
26
+ @sport = type
26
27
  end
27
28
 
28
29
  ##
29
- # Building a new Info object.
30
+ # Adding an info message to the object.
30
31
  # Params:
31
32
  # +message+:: the info message
32
33
  def info(message)
33
- @info << Info.new(message)
34
+ @info = message
34
35
  end
35
36
 
36
37
  ##
37
- # Building a new AverageHeartRate object.
38
+ # Adding a speed duration of an interval to the object.
38
39
  # Params:
39
- # +heart_rate+:: the average heart rate in bpm
40
- def average_heart_rate(heart_rate)
41
- @average_heart_rate << AverageHeartRate.new(heart_rate)
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
42
43
  end
43
44
 
44
45
  ##
45
- # Building a new TotalDuration object.
46
+ # Adding a recovery duration of an interval to the object.
46
47
  # Params:
47
- # +duration+:: the duration in seconds
48
- def total_duration(duration)
49
- @total_duration << TotalDuration.new(duration)
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
50
51
  end
51
52
 
52
53
  ##
53
- # Building a new AverageHeartRateRest object.
54
+ # Adding a speed heart rate of an interval to the object.
54
55
  # Params:
55
- # +heart_rate_rest+:: the average rest heart rate in bpm
56
- def average_heart_rate_rest(heart_rate_rest)
57
- @average_heart_rate_rest << AverageHeartRateRest.new(heart_rate_rest)
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
58
59
  end
59
60
 
60
61
  ##
61
- # Building a new TotalDurationRest object.
62
+ # Adding a recovery heart rate of an interval to the object.
62
63
  # Params:
63
- # +duration rest+:: the rest duration in seconds
64
- def total_duration_rest(duration_rest)
65
- @total_duration_rest << TotalDurationRest.new(duration_rest)
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
68
+
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
66
75
  end
67
76
 
68
77
  ##
69
78
  # Converting an interval to a string.
70
79
  def to_s
71
- "#{@sport[0].type} #{@info[0].message}"
80
+ "#{@sport} #{@info}"
72
81
  end
73
82
 
74
83
  ##
75
84
  # Converting an interval to a JSON-ized string.
76
85
  def to_hash
77
- {
78
- name: @name.collect(&:to_hash),
79
- sport: @sport.collect(&:to_hash),
80
- info: @info.collect(&:to_hash),
81
- average_heart_rate: @average_heart_rate.collect(&:to_hash),
82
- total_duration: @total_duration.collect(&:to_hash),
83
- average_heart_rate_rest: @average_heart_rate_rest.collect(&:to_hash),
84
- total_duration_rest: @total_duration_rest.collect(&: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
85
95
  }
96
+
97
+ hash[:info] = @info if @info
98
+ hash
86
99
  end
87
100
  end
data/lib/session.rb CHANGED
@@ -7,61 +7,63 @@ class Session
7
7
  # Initialization method for the +Session+ class.
8
8
  # Params:
9
9
  # +name+:: the name of the session
10
- def initialize(_name)
11
- @name = []
12
- @sport = []
13
- @info = []
14
- @average_heart_rate = []
15
- @total_duration = []
10
+ def initialize(name)
11
+ @name = name
12
+ @sport = ''
13
+ @info = ''
14
+ @average_heart_rate = 0
15
+ @total_duration = 0
16
16
  end
17
17
 
18
18
  ##
19
- # Building a new Sport object.
19
+ # Adding a sport type to the object.
20
20
  # Params:
21
21
  # +type+:: the type of the sport
22
22
  def sport(type)
23
- @sport << Sport.new(type)
23
+ @sport = type
24
24
  end
25
25
 
26
26
  ##
27
- # Building a new Info object.
27
+ # Adding a message to the object.
28
28
  # Params:
29
29
  # +message+:: the info message
30
30
  def info(message)
31
- @info << Info.new(message)
31
+ @info = message
32
32
  end
33
33
 
34
34
  ##
35
- # Building a new AverageHeartRate object.
35
+ # Adding an average heart rate to the object.
36
36
  # Params:
37
37
  # +heart_rate+:: the average heart rate in bpm
38
38
  def average_heart_rate(heart_rate)
39
- @average_heart_rate << AverageHeartRate.new(heart_rate)
39
+ @average_heart_rate = heart_rate.to_s.to_i
40
40
  end
41
41
 
42
42
  ##
43
- # Building a new TotalDuration object.
43
+ # Adding a total duration to the object.
44
44
  # Params:
45
- # +duration+:: the duration in seconds
45
+ # +duration+:: the duration in minutes
46
46
  def total_duration(duration)
47
- @total_duration << TotalDuration.new(duration)
47
+ @total_duration = duration.to_s.to_i
48
48
  end
49
49
 
50
50
  ##
51
51
  # Converting a session to a string.
52
52
  def to_s
53
- "#{@sport[0].type} #{@info[0].message}"
53
+ "#{@sport} #{@info}"
54
54
  end
55
55
 
56
56
  ##
57
57
  # Converting a session to a JSON-ized string.
58
58
  def to_hash
59
- {
60
- name: @name.collect(&:to_hash),
61
- sport: @sport.collect(&:to_hash),
62
- info: @info.collect(&:to_hash),
63
- average_heart_rate: @average_heart_rate.collect(&:to_hash),
64
- total_duration: @total_duration.collect(&:to_hash),
59
+ hash = {
60
+ name: @name,
61
+ sport: @sport,
62
+ average_heart_rate: @average_heart_rate,
63
+ total_duration: @total_duration,
65
64
  }
65
+
66
+ hash[:info] = @info if @info != ''
67
+ hash
66
68
  end
67
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.4
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-28 00:00:00.000000000 Z
12
+ date: 2022-07-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -23,7 +23,6 @@ files:
23
23
  - README.md
24
24
  - lib/ast-tdl.rb
25
25
  - lib/ast.rb
26
- - lib/classes.rb
27
26
  - lib/interval.rb
28
27
  - lib/session.rb
29
28
  homepage: https://github.com/firefly-cpp/ast-tdl
data/lib/classes.rb DELETED
@@ -1,148 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- ##
6
- # This class represents a sport with a type.
7
- class Sport
8
- # The type of a sport.
9
- attr_reader :type
10
-
11
- ##
12
- # Initialization method for the +Sport+ class.
13
- # Params:
14
- # +type+:: the type of the sport
15
- def initialize(type)
16
- @type = type
17
- end
18
-
19
- ##
20
- # Converting +Sport+ class to a hash.
21
- def to_hash
22
- {
23
- type: @type
24
- }
25
- end
26
- end
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
- {
46
- message: @message
47
- }
48
- end
49
- end
50
-
51
- ##
52
- # This class represents an average heart rate.
53
- class AverageHeartRate
54
- # An average heart rate.
55
- attr_reader :heart_rate
56
-
57
- ##
58
- # Initialization method for the +AverageHeartRate+ class.
59
- # Params:
60
- # +heart_rate+:: the average heart rate
61
- def initialize(heart_rate)
62
- heart_rate = heart_rate.to_s.to_i
63
- raise ArgumentError, 'Maximum heart rate is 220.' if heart_rate > 220
64
-
65
- @heart_rate = heart_rate
66
- end
67
-
68
- ##
69
- # Converting +AverageHeartRate+ class to a hash.
70
- def to_hash
71
- {
72
- average_hr: @heart_rate
73
- }
74
- end
75
- end
76
-
77
- ##
78
- # This class represents a total duration of a session or an interval.
79
- class TotalDuration
80
- # The total duration in seconds.
81
- attr_reader :duration
82
-
83
- ##
84
- # Initialization method for the +TotalDuration+ class.
85
- # Params:
86
- # +duration+:: the total duration
87
- def initialize(duration)
88
- @duration = duration
89
- end
90
-
91
- ##
92
- # Converting +TotalDuration+ class to a hash.
93
- def to_hash
94
- {
95
- duration: @duration
96
- }
97
- end
98
- end
99
-
100
- ##
101
- # This class represents an average heart rate in the resting period.
102
- class AverageHeartRateRest
103
- # The average rest heart rate.
104
- attr_reader :average_heart_rate_rest
105
-
106
- ##
107
- # Initialization method for the +AverageHeartRateRest+ class.
108
- # Params:
109
- # +average_heart_rate_rest+:: the average heart rate
110
- def initialize(average_heart_rate_rest)
111
- average_heart_rate_rest = average_heart_rate_rest.to_s.to_i
112
- raise ArgumentError, 'Maximum heart rate is 220.' if average_heart_rate_rest > 220
113
-
114
- @average_heart_rate_rest = average_heart_rate_rest
115
- end
116
-
117
- ##
118
- # Converting +AverageHeartRateRest+ class to a hash.
119
- def to_hash
120
- {
121
- average_heart_rate_rest: @average_heart_rate_rest
122
- }
123
- end
124
- end
125
-
126
- ##
127
- # This class represents a total duration of a session or an
128
- # interval in the resting period.
129
- class TotalDurationRest
130
- # The total duration in seconds.
131
- attr_reader :total_duration_rest
132
-
133
- ##
134
- # Initialization method for the +TotalDurationRest+ class.
135
- # Params:
136
- # +total_duration_rest+:: the total rest duration
137
- def initialize(total_duration_rest)
138
- @total_duration_rest = total_duration_rest
139
- end
140
-
141
- ##
142
- # Converting +TotalDurationRest+ class to a hash.
143
- def to_hash
144
- {
145
- total_duration_rest: @total_duration_rest
146
- }
147
- end
148
- end