ast-tdl 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +35 -12
 - data/lib/ast-tdl.rb +3 -1
 - data/lib/ast.rb +72 -73
 - data/lib/classes.rb +117 -125
 - data/lib/interval.rb +79 -77
 - data/lib/session.rb +58 -56
 - metadata +9 -8
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: acbbd1f514fbcdc7f7c30925602170f3ebe829f688dbf3e562488f9fc88ed87f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 554f179dec696c7d330acb1884aed681f88f1a03923bd4353eef68bd9ddb2b81
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2ffa95b47ee68c9091883a974fc84c3c91143594948bd22459a5d462209c877ee9f00919ca1e055b925d8ff35d8f6262f9f40f6e525b4cf9c8931d9827a923ec
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 995761ca6d201f99b4cf9f3fc061279e5332b197b83161e52fa0792a7af3f1d7f4434f4eef4e3d9e3552fdb87cdda0881dd075d9fc380c07f10339d36b462e78
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,33 +1,56 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Training Description Language (TDL) for Artificial Sport Trainer (AST)
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            AST-DSL is a very small domain-specific language
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            ## Objective
         
     | 
| 
      
 2 
     | 
    
         
            +
            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.
         
     | 
| 
       6 
3 
     | 
    
         | 
| 
       7 
4 
     | 
    
         
             
            ## Installation
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
5 
     | 
    
         
             
                $ gem install ast-tdl
         
     | 
| 
       10 
6 
     | 
    
         | 
| 
       11 
7 
     | 
    
         
             
            ## Language description
         
     | 
| 
      
 8 
     | 
    
         
            +
            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 
9 
     | 
    
         | 
| 
       13 
10 
     | 
    
         
             
            ## Examples
         
     | 
| 
      
 11 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 12 
     | 
    
         
            +
            EasyTraining = Ast.build :Monday do
         
     | 
| 
      
 13 
     | 
    
         
            +
                session("Short swimming session today") {
         
     | 
| 
      
 14 
     | 
    
         
            +
            	sport               :"swim"
         
     | 
| 
      
 15 
     | 
    
         
            +
            	info                :"Very easy training"
         
     | 
| 
      
 16 
     | 
    
         
            +
                    average_heart_rate  :"130"
         
     | 
| 
      
 17 
     | 
    
         
            +
                    total_duration      :"30"
         
     | 
| 
      
 18 
     | 
    
         
            +
                }
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                session("Bike ride") {
         
     | 
| 
      
 21 
     | 
    
         
            +
                    sport               :"bike"
         
     | 
| 
      
 22 
     | 
    
         
            +
            	info                :"Endurance ride with intervals"
         
     | 
| 
      
 23 
     | 
    
         
            +
            	average_heart_rate  :"140"
         
     | 
| 
      
 24 
     | 
    
         
            +
            	total_duration      :"250"
         
     | 
| 
      
 25 
     | 
    
         
            +
                }
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                interval("Number 1") {
         
     | 
| 
      
 28 
     | 
    
         
            +
            	sport                   :"swim"
         
     | 
| 
      
 29 
     | 
    
         
            +
            	info                    :"Moderate"
         
     | 
| 
      
 30 
     | 
    
         
            +
                    average_heart_rate      :"160"
         
     | 
| 
      
 31 
     | 
    
         
            +
                    total_duration          :"5"
         
     | 
| 
      
 32 
     | 
    
         
            +
                    average_heart_rate_rest :"90"
         
     | 
| 
      
 33 
     | 
    
         
            +
                    total_duration_rest     :"2"
         
     | 
| 
      
 34 
     | 
    
         
            +
                }
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
      
 36 
     | 
    
         
            +
            ```
         
     | 
| 
       14 
37 
     | 
    
         | 
| 
       15 
38 
     | 
    
         
             
            ### Session
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
39 
     | 
    
         
             
            ```ruby
         
     | 
| 
       18 
40 
     | 
    
         
             
            session("Short swimming session today") {
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
      
 41 
     | 
    
         
            +
                sport 	        :"swim"
         
     | 
| 
      
 42 
     | 
    
         
            +
                info                :"Very easy training"
         
     | 
| 
      
 43 
     | 
    
         
            +
                average_heart_rate  :"130"
         
     | 
| 
      
 44 
     | 
    
         
            +
                total_duration      :"30"
         
     | 
| 
       23 
45 
     | 
    
         
             
            }
         
     | 
| 
       24 
46 
     | 
    
         
             
            ```
         
     | 
| 
       25 
     | 
    
         
            -
            ## License
         
     | 
| 
       26 
47 
     | 
    
         | 
| 
      
 48 
     | 
    
         
            +
            ## License
         
     | 
| 
       27 
49 
     | 
    
         
             
            This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
         
     | 
| 
       28 
50 
     | 
    
         | 
| 
       29 
51 
     | 
    
         
             
            ## Disclaimer
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
52 
     | 
    
         
             
            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 
53 
     | 
    
         | 
| 
      
 54 
     | 
    
         
            +
            ## References
         
     | 
| 
       33 
55 
     | 
    
         | 
| 
      
 56 
     | 
    
         
            +
            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
    
    
    
        data/lib/ast.rb
    CHANGED
    
    | 
         @@ -1,86 +1,85 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       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 'classes'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative 'interval'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative 'session'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            ##
         
     | 
| 
       9 
9 
     | 
    
         
             
            # This module is intended to be used for building trainings
         
     | 
| 
       10 
10 
     | 
    
         
             
            # from the domain specific language AST-TDL.
         
     | 
| 
       11 
11 
     | 
    
         
             
            module Ast
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            +
                training
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
       23 
22 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
              ##
         
     | 
| 
      
 24 
     | 
    
         
            +
              # This class represents a training with a name, sessions and intervals.
         
     | 
| 
      
 25 
     | 
    
         
            +
              class Training
         
     | 
| 
      
 26 
     | 
    
         
            +
                ##
         
     | 
| 
      
 27 
     | 
    
         
            +
                # Initialization method for the +Training+ class.
         
     | 
| 
      
 28 
     | 
    
         
            +
                # Params:
         
     | 
| 
      
 29 
     | 
    
         
            +
                # +name+:: the name of the training
         
     | 
| 
      
 30 
     | 
    
         
            +
                def initialize(name)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @name = name
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @session = []
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @interval = []
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
       36 
35 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
                ##
         
     | 
| 
      
 37 
     | 
    
         
            +
                # Building a new session from the domain specific language.
         
     | 
| 
      
 38 
     | 
    
         
            +
                # Params:
         
     | 
| 
      
 39 
     | 
    
         
            +
                # +name+:: the name of the session
         
     | 
| 
      
 40 
     | 
    
         
            +
                # +block+:: session data
         
     | 
| 
      
 41 
     | 
    
         
            +
                def session(name, &block)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  training_type = Session.new(name)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  training_type.instance_eval(&block)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @session << training_type
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
       47 
46 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
                ##
         
     | 
| 
      
 48 
     | 
    
         
            +
                # Building a new interval from the domain specific language.
         
     | 
| 
      
 49 
     | 
    
         
            +
                # Params:
         
     | 
| 
      
 50 
     | 
    
         
            +
                # +name+:: the name of the interval
         
     | 
| 
      
 51 
     | 
    
         
            +
                # +block+:: interval data
         
     | 
| 
      
 52 
     | 
    
         
            +
                def interval(name, &block)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  interval_data = Interval.new(name)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  interval_data.instance_eval(&block)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  @interval << interval_data
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
       58 
57 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
                ##
         
     | 
| 
      
 59 
     | 
    
         
            +
                # Converting a training to a string.
         
     | 
| 
      
 60 
     | 
    
         
            +
                def to_s
         
     | 
| 
      
 61 
     | 
    
         
            +
                  "#{@name} #{@session[0]}"
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
       64 
63 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                ##
         
     | 
| 
      
 65 
     | 
    
         
            +
                # Converting a training to a JSON-ized string.
         
     | 
| 
      
 66 
     | 
    
         
            +
                def json
         
     | 
| 
      
 67 
     | 
    
         
            +
                  training_json = {
         
     | 
| 
      
 68 
     | 
    
         
            +
                    name: @name,
         
     | 
| 
      
 69 
     | 
    
         
            +
                    session: @session.collect(&:to_hash),
         
     | 
| 
      
 70 
     | 
    
         
            +
                    interval: @interval.collect(&:to_hash)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  }
         
     | 
| 
      
 72 
     | 
    
         
            +
                  training_json.to_json
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
       75 
74 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
      
 75 
     | 
    
         
            +
                ##
         
     | 
| 
      
 76 
     | 
    
         
            +
                # Saving a training to a JSON file.
         
     | 
| 
      
 77 
     | 
    
         
            +
                # Params:
         
     | 
| 
      
 78 
     | 
    
         
            +
                # +filename+:: the desired name of the file
         
     | 
| 
      
 79 
     | 
    
         
            +
                def save_to_file(filename)
         
     | 
| 
      
 80 
     | 
    
         
            +
                  f = File.open(filename, 'w')
         
     | 
| 
      
 81 
     | 
    
         
            +
                  f.puts(json)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  f.close
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
              end
         
     | 
| 
       86 
85 
     | 
    
         
             
            end
         
     | 
    
        data/lib/classes.rb
    CHANGED
    
    | 
         @@ -1,156 +1,148 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            require 'json'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            ##
         
     | 
| 
       5 
6 
     | 
    
         
             
            # This class represents a sport with a type.
         
     | 
| 
       6 
7 
     | 
    
         
             
            class Sport
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       25 
26 
     | 
    
         
             
            end
         
     | 
| 
       26 
27 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
28 
     | 
    
         
             
            ##
         
     | 
| 
       29 
29 
     | 
    
         
             
            # This class represents information with a message.
         
     | 
| 
       30 
30 
     | 
    
         
             
            class Info
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 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 
49 
     | 
    
         
             
            end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
51 
     | 
    
         
             
            ##
         
     | 
| 
       53 
52 
     | 
    
         
             
            # This class represents an average heart rate.
         
     | 
| 
       54 
53 
     | 
    
         
             
            class AverageHeartRate
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
            		}
         
     | 
| 
       77 
     | 
    
         
            -
            	end
         
     | 
| 
      
 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
         
     | 
| 
       78 
75 
     | 
    
         
             
            end
         
     | 
| 
       79 
76 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
77 
     | 
    
         
             
            ##
         
     | 
| 
       82 
78 
     | 
    
         
             
            # This class represents a total duration of a session or an interval.
         
     | 
| 
       83 
79 
     | 
    
         
             
            class TotalDuration
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       102 
98 
     | 
    
         
             
            end
         
     | 
| 
       103 
99 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
100 
     | 
    
         
             
            ##
         
     | 
| 
       106 
101 
     | 
    
         
             
            # This class represents an average heart rate in the resting period.
         
     | 
| 
       107 
102 
     | 
    
         
             
            class AverageHeartRateRest
         
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
            		}
         
     | 
| 
       130 
     | 
    
         
            -
            	end
         
     | 
| 
      
 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
         
     | 
| 
       131 
124 
     | 
    
         
             
            end
         
     | 
| 
       132 
125 
     | 
    
         | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
126 
     | 
    
         
             
            ##
         
     | 
| 
       135 
127 
     | 
    
         
             
            # This class represents a total duration of a session or an
         
     | 
| 
       136 
128 
     | 
    
         
             
            # interval in the resting period.
         
     | 
| 
       137 
129 
     | 
    
         
             
            class TotalDurationRest
         
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
            end
         
     | 
| 
      
 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
         
     | 
    
        data/lib/interval.rb
    CHANGED
    
    | 
         @@ -1,85 +1,87 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            ##
         
     | 
| 
       2 
4 
     | 
    
         
             
            # This class represents an interval.
         
     | 
| 
       3 
5 
     | 
    
         
             
            class Interval
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
              ##
         
     | 
| 
      
 7 
     | 
    
         
            +
              # Initialization method for the +Interval+ class.
         
     | 
| 
      
 8 
     | 
    
         
            +
              # Params:
         
     | 
| 
      
 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 = []
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              ##
         
     | 
| 
      
 21 
     | 
    
         
            +
              # Building a new Sport object.
         
     | 
| 
      
 22 
     | 
    
         
            +
              # Params:
         
     | 
| 
      
 23 
     | 
    
         
            +
              # +type+:: the type of the sport
         
     | 
| 
      
 24 
     | 
    
         
            +
              def sport(type)
         
     | 
| 
      
 25 
     | 
    
         
            +
                @sport << Sport.new(type)
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              ##
         
     | 
| 
      
 29 
     | 
    
         
            +
              # Building a new Info object.
         
     | 
| 
      
 30 
     | 
    
         
            +
              # Params:
         
     | 
| 
      
 31 
     | 
    
         
            +
              # +message+:: the info message
         
     | 
| 
      
 32 
     | 
    
         
            +
              def info(message)
         
     | 
| 
      
 33 
     | 
    
         
            +
                @info << Info.new(message)
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              ##
         
     | 
| 
      
 37 
     | 
    
         
            +
              # Building a new AverageHeartRate object.
         
     | 
| 
      
 38 
     | 
    
         
            +
              # 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)
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
       17 
43 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
              ##
         
     | 
| 
      
 45 
     | 
    
         
            +
              # Building a new TotalDuration object.
         
     | 
| 
      
 46 
     | 
    
         
            +
              # Params:
         
     | 
| 
      
 47 
     | 
    
         
            +
              # +duration+:: the duration in seconds
         
     | 
| 
      
 48 
     | 
    
         
            +
              def total_duration(duration)
         
     | 
| 
      
 49 
     | 
    
         
            +
                @total_duration << TotalDuration.new(duration)
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
       25 
51 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
              ##
         
     | 
| 
      
 53 
     | 
    
         
            +
              # Building a new AverageHeartRateRest object.
         
     | 
| 
      
 54 
     | 
    
         
            +
              # 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)
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
       33 
59 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
              ##
         
     | 
| 
      
 61 
     | 
    
         
            +
              # Building a new TotalDurationRest object.
         
     | 
| 
      
 62 
     | 
    
         
            +
              # Params:
         
     | 
| 
      
 63 
     | 
    
         
            +
              # +duration rest+:: the rest duration in seconds
         
     | 
| 
      
 64 
     | 
    
         
            +
              def total_duration_rest(duration_rest)
         
     | 
| 
      
 65 
     | 
    
         
            +
                @total_duration_rest << TotalDurationRest.new(duration_rest)
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
       41 
67 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       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
         
     | 
| 
      
 68 
     | 
    
         
            +
              ##
         
     | 
| 
      
 69 
     | 
    
         
            +
              # Converting an interval to a string.
         
     | 
| 
      
 70 
     | 
    
         
            +
              def to_s
         
     | 
| 
      
 71 
     | 
    
         
            +
                "#{@sport[0].type} #{@info[0].message}"
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
       71 
73 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
            end
         
     | 
| 
      
 74 
     | 
    
         
            +
              ##
         
     | 
| 
      
 75 
     | 
    
         
            +
              # Converting an interval to a JSON-ized string.
         
     | 
| 
      
 76 
     | 
    
         
            +
              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),
         
     | 
| 
      
 85 
     | 
    
         
            +
                }
         
     | 
| 
      
 86 
     | 
    
         
            +
              end
         
     | 
| 
      
 87 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/session.rb
    CHANGED
    
    | 
         @@ -1,65 +1,67 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            ##
         
     | 
| 
       2 
4 
     | 
    
         
             
            # This class represents a session.
         
     | 
| 
       3 
5 
     | 
    
         
             
            class Session
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
              ##
         
     | 
| 
      
 7 
     | 
    
         
            +
              # Initialization method for the +Session+ class.
         
     | 
| 
      
 8 
     | 
    
         
            +
              # Params:
         
     | 
| 
      
 9 
     | 
    
         
            +
              # +name+:: the name of the session
         
     | 
| 
      
 10 
     | 
    
         
            +
              def initialize(_name)
         
     | 
| 
      
 11 
     | 
    
         
            +
                @name = []
         
     | 
| 
      
 12 
     | 
    
         
            +
                @sport = []
         
     | 
| 
      
 13 
     | 
    
         
            +
                @info = []
         
     | 
| 
      
 14 
     | 
    
         
            +
                @average_heart_rate = []
         
     | 
| 
      
 15 
     | 
    
         
            +
                @total_duration = []
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       31 
33 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       39 
41 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       47 
49 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
              ##
         
     | 
| 
      
 51 
     | 
    
         
            +
              # Converting a session to a string.
         
     | 
| 
      
 52 
     | 
    
         
            +
              def to_s
         
     | 
| 
      
 53 
     | 
    
         
            +
                "#{@sport[0].type} #{@info[0].message}"
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
       53 
55 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
            end
         
     | 
| 
      
 56 
     | 
    
         
            +
              ##
         
     | 
| 
      
 57 
     | 
    
         
            +
              # Converting a session to a JSON-ized string.
         
     | 
| 
      
 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),
         
     | 
| 
      
 65 
     | 
    
         
            +
                }
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
            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 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
       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- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2022-06-23 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       14 
14 
     | 
    
         
             
            description:
         
     | 
| 
       15 
15 
     | 
    
         
             
            email:
         
     | 
| 
         @@ -25,12 +25,13 @@ files: 
     | 
|
| 
       25 
25 
     | 
    
         
             
            - lib/classes.rb
         
     | 
| 
       26 
26 
     | 
    
         
             
            - lib/interval.rb
         
     | 
| 
       27 
27 
     | 
    
         
             
            - lib/session.rb
         
     | 
| 
       28 
     | 
    
         
            -
            homepage: https://github.com/firefly-cpp/ 
     | 
| 
       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/ 
     | 
| 
       32 
     | 
    
         
            -
              source_code_uri: https://github.com/firefly-cpp/ 
     | 
| 
       33 
     | 
    
         
            -
              changelog_uri: https://github.com/firefly-cpp/ 
     | 
| 
      
 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. 
     | 
| 
      
 43 
     | 
    
         
            +
                  version: 2.6.0
         
     | 
| 
       43 
44 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       44 
45 
     | 
    
         
             
              requirements:
         
     | 
| 
       45 
46 
     | 
    
         
             
              - - ">="
         
     |