calcpace 0.1.0
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 +7 -0
- data/lib/calcpace/calculator.rb +25 -0
- data/lib/calcpace/checker.rb +20 -0
- data/lib/calcpace/converter.rb +22 -0
- data/lib/calcpace.rb +13 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 11ad12749e77c35206d4753b60f3db604ea548ab75724d1602606c9cb9eca196
|
4
|
+
data.tar.gz: fb65325f6210995dd7f64f0b1707e328a77e08b83a85dbfc0644bec1de7e6548
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61b82828b6d43b293744526ac4f34e434df820c19be0a8378e3cbfbe0995e357aaefb6a1caedb50831f5b7c81a9776d64ac599a5a3e858979b7b549737a6d5b9
|
7
|
+
data.tar.gz: e4d9c623fbf2c0a9ab4d9953cadbed377b7867a3c3b0be494fd572860bf467c5ae88cfbd80d038e4157fcea44b799f2cc4d476598a6f621b2d85057fca51958e
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Calculator
|
4
|
+
def pace(time, distance)
|
5
|
+
check_digits(time, distance)
|
6
|
+
convert_to_clocktime(convert_to_seconds(time) / distance.to_f)
|
7
|
+
end
|
8
|
+
|
9
|
+
def total_time(pace, distance)
|
10
|
+
check_digits(pace, distance)
|
11
|
+
convert_to_clocktime(convert_to_seconds(pace) * distance.to_f)
|
12
|
+
end
|
13
|
+
|
14
|
+
def distance(time, pace)
|
15
|
+
check_digits_time(time)
|
16
|
+
check_digits_time(pace)
|
17
|
+
convert_to_seconds(time).to_f / convert_to_seconds(pace).round(2)
|
18
|
+
end
|
19
|
+
|
20
|
+
def convert_distance(distance, unit)
|
21
|
+
check_digits_distance(distance)
|
22
|
+
check_unit(unit)
|
23
|
+
convert(distance, unit)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Checker
|
4
|
+
def check_digits(time, distance)
|
5
|
+
check_digits_time(time)
|
6
|
+
check_digits_distance(distance)
|
7
|
+
end
|
8
|
+
|
9
|
+
def check_digits_distance(distance)
|
10
|
+
raise 'It must be a X.X positive number' unless distance.positive?
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_digits_time(time_string)
|
14
|
+
raise 'It must be a XX:XX:XX time' unless time_string =~ /\d{0,2}(:)*?\d{1,2}(:)\d{1,2}/
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_unit(unit)
|
18
|
+
raise 'It must be km or mi' unless %w[km mi].include?(unit)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
def convert_to_seconds(time)
|
5
|
+
hour, minute, seconds = time.split(':').map(&:to_i)
|
6
|
+
(hour * 3600) + (minute * 60) + seconds
|
7
|
+
end
|
8
|
+
|
9
|
+
def convert_to_clocktime(seconds)
|
10
|
+
Time.at(seconds).utc.strftime('%H:%M:%S')
|
11
|
+
end
|
12
|
+
|
13
|
+
# tem que chamar as checagens de digitos antes de chamar o convert_distance
|
14
|
+
def convert(distance, unit)
|
15
|
+
case unit
|
16
|
+
when 'km'
|
17
|
+
(distance * 0.621371).round(2)
|
18
|
+
when 'mi'
|
19
|
+
(distance * 1.60934).round(2)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/calcpace.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'calcpace/calculator'
|
4
|
+
require_relative 'calcpace/checker'
|
5
|
+
require_relative 'calcpace/converter'
|
6
|
+
|
7
|
+
class Calcpace
|
8
|
+
include Calculator
|
9
|
+
include Checker
|
10
|
+
include Converter
|
11
|
+
|
12
|
+
def initialize; end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: calcpace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joao Gilberto Saraiva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Calculate pace, time, distance, and convert distances for running and
|
14
|
+
cycling.
|
15
|
+
email: joaogilberto@tuta.io
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/calcpace.rb
|
21
|
+
- lib/calcpace/calculator.rb
|
22
|
+
- lib/calcpace/checker.rb
|
23
|
+
- lib/calcpace/converter.rb
|
24
|
+
homepage: https://github.com/0jonjo/calcpace
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubygems_version: 3.2.33
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Calcpace
|
47
|
+
test_files: []
|