calcpace 1.5.5 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '04889c91e456d34e17974f8aeafa14bb99c0f44957bb42fdc6cac4a3c1a87bf1'
4
- data.tar.gz: 60b0d8e24f2f10905c8ee8697c892b63efef0fca92fecb42dc86e9cf797b37a9
3
+ metadata.gz: d05362249daa1675ba18bb4f6dfc65b79d3380787d451e64b55bc436e3952381
4
+ data.tar.gz: 3374e54393bb54e443c9feb610e05caf36842d5d1c1d5ceb3e517bc79022f6ef
5
5
  SHA512:
6
- metadata.gz: af863c188a3e74b28211bac8956c5fd1ad7440e9cdb8316f5c329a06daf5387ad81ecdeacced1b0011bfad304b0f8b9607c9deeca63dfba628e04162c718cb1f
7
- data.tar.gz: ba0a4e7fd03714ca47c9a1cb9b1d8081327e2821b9da44730866437e3ba54c74aec43d93ae9f2f75ac69f7fe1672ee4fb62f4c17f015a35a83045583ebe872e4
6
+ metadata.gz: bb5a709698a85d9169ec683a47992eb2dfaf4dfdad430ef4a949b525896378814061a7f31a8f906f7475ff39c141e51e939a5847178baea87e1be9a69cc3015a
7
+ data.tar.gz: af509b94cb168456939af0329bcc93ee7c7cd0bdb95a8951c34267cfb175681f72ae02c8191671203feb988f30f89d673ef32bb87c197712c960a5febdc4a25b
@@ -1,4 +1,6 @@
1
1
  name: Tests
2
+ permissions:
3
+ contents: read
2
4
  on:
3
5
  push:
4
6
  branches: [ "main" ]
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.2
1
+ 3.4.4
data/.tool-versions ADDED
@@ -0,0 +1,2 @@
1
+ nodejs 24.1.0
2
+ ruby 3.4.4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Calcpace [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&r=r&ts=1683906897&type=6e&v=1.5.5&x2=0)](https://badge.fury.io/rb/calcpace)
1
+ # Calcpace [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&r=r&ts=1683906897&type=6e&v=1.6.0&x2=0)](https://badge.fury.io/rb/calcpace)
2
2
 
3
3
  Calcpace is a Ruby gem designed for calculations and conversions related to distance and time. It can calculate velocity, pace, total time, and distance, accepting time in various formats, including HH:MM:SS. The gem supports conversion to 42 different units, including kilometers, miles, meters, and feet. It also provides methods to validate input.
4
4
 
@@ -7,7 +7,7 @@ Calcpace is a Ruby gem designed for calculations and conversions related to dist
7
7
  ### Add to your Gemfile
8
8
 
9
9
  ```ruby
10
- gem 'calcpace', '~> 1.5.5'
10
+ gem 'calcpace', '~> 1.6.0'
11
11
  ```
12
12
 
13
13
  Then run:
@@ -87,15 +87,15 @@ To learn more about BigDecimal, check the [documentation](https://ruby-doc.org/s
87
87
 
88
88
  ### Convert Distances and Velocities
89
89
 
90
- Use the `convert` method to convert a distance or velocity. The first parameter is the value to be converted, and the second parameter is the unit to which the value will be converted. The unit must be a string with the abbreviation of the unit. The gem supports 26 different units, including kilometers, miles, meters, knots, and feet.
90
+ Use the `convert` method to convert a distance or velocity. The first parameter is the value to be converted, and the second parameter is the unit to which the value will be converted. The unit can be a string (e.g. 'km to meters') or a symbol (e.g. :km_to_meters). The gem supports 42 different units, including kilometers, miles, meters, knots, and feet.
91
91
 
92
92
  Here are some examples:
93
93
 
94
94
  ```ruby
95
95
  converter.convert(10, :km_to_meters) # => 1000
96
- converter.convert(10, :mi_to_km) # => 16.0934
96
+ converter.convert(10, 'mi to km') # => 16.0934
97
97
  converter.convert(1, :nautical_mi_to_km) # => 1.852
98
- converter.convert(1, :km_h_to_m_s) # => 0.277778
98
+ converter.convert(1, 'km h to m s') # => 0.277778
99
99
  converter.convert(1, :m_s_to_mi_h) # => 2.23694
100
100
  ```
101
101
 
@@ -118,12 +118,17 @@ converter.convert(1, :m_s_to_mi_h) # => 2.23694
118
118
  | :km_h_to_mi_h | Kilometers per Hour to Miles per Hour |
119
119
  | :mi_h_to_km_h | Miles per Hour to Kilometers per Hour |
120
120
 
121
- You can list all the available units [here](/lib/calcpace/converter.rb), or using `list` methods:
121
+ You can list all the available units [here](/lib/calcpace/converter.rb), or using `list` methods. The return will be a hash with the unit and a description of the unit.
122
122
 
123
123
  ```ruby
124
124
  converter.list_all
125
+ # => {:km_to_mi=>"KM to MI", :mi_to_km=>"MI to KM", ...}
126
+
125
127
  converter.list_distance
128
+ # => {:km_to_mi=>"KM to MI", :mi_to_km=>"MI to KM", ...}
129
+
126
130
  converter.list_speed
131
+ # => {:m_s_to_km_h=>"M S to KM H", :km_h_to_m_s=>"KM H to M S", ...}
127
132
  ```
128
133
 
129
134
  ### Other Useful Methods
@@ -151,7 +156,7 @@ For example:
151
156
  begin
152
157
  calculate.pace(945, -1)
153
158
  rescue Calcpace::NonPositiveInputError => e
154
- puts e.message # => "Input must be a positive number"
159
+ puts e.message # => "Distance must be a positive number"
155
160
  end
156
161
 
157
162
  begin
data/calcpace.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/calcpace/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -3,7 +3,7 @@
3
3
  # Module to calculate time, distance, pace and velocity
4
4
  module Calculator
5
5
  def velocity(time, distance)
6
- validate_positive(time, distance)
6
+ validate_positive({ time: time, distance: distance })
7
7
  distance.to_f / time
8
8
  end
9
9
 
@@ -17,7 +17,7 @@ module Calculator
17
17
  end
18
18
 
19
19
  def pace(time, distance)
20
- validate_positive(time, distance)
20
+ validate_positive({ time: time, distance: distance })
21
21
  time.to_f / distance
22
22
  end
23
23
 
@@ -31,7 +31,7 @@ module Calculator
31
31
  end
32
32
 
33
33
  def time(velocity, distance)
34
- validate_positive(velocity, distance)
34
+ validate_positive({ velocity: velocity, distance: distance })
35
35
  velocity * distance
36
36
  end
37
37
 
@@ -45,7 +45,7 @@ module Calculator
45
45
  end
46
46
 
47
47
  def distance(time, velocity)
48
- validate_positive(time, velocity)
48
+ validate_positive({ time: time, velocity: velocity })
49
49
  time.to_f / velocity
50
50
  end
51
51
 
@@ -57,8 +57,8 @@ module Calculator
57
57
 
58
58
  private
59
59
 
60
- def validate_positive(*values)
61
- values.each { |value| check_positive(value) }
60
+ def validate_positive(values)
61
+ values.each { |name, value| check_positive(value, name.capitalize) }
62
62
  end
63
63
 
64
64
  def validate_time(time)
@@ -4,11 +4,11 @@ require_relative 'errors'
4
4
 
5
5
  # Module to check if the input is valid or of the correct type
6
6
  module Checker
7
- def check_positive(number)
7
+ def check_positive(number, name = 'Input')
8
8
  return if number.is_a?(Numeric) && number.positive?
9
9
 
10
10
  raise Calcpace::NonPositiveInputError,
11
- 'It must be a positive number'
11
+ "#{name} must be a positive number"
12
12
  end
13
13
 
14
14
  def check_time(time_string)
@@ -51,7 +51,7 @@ module Converter
51
51
  end
52
52
 
53
53
  def convert(value, unit)
54
- check_positive(value)
54
+ check_positive(value, 'Value')
55
55
  unit_constant = constant(unit)
56
56
  value * unit_constant
57
57
  end
@@ -73,21 +73,32 @@ module Converter
73
73
  Time.at(seconds).utc.strftime(format)
74
74
  end
75
75
 
76
- def constant(symbol)
77
- Distance.const_get(symbol.to_s.upcase)
76
+ def constant(unit)
77
+ unit = format_unit(unit) if unit.is_a?(String)
78
+ Distance.const_get(unit.to_s.upcase)
78
79
  rescue NameError
79
- Speed.const_get(symbol.to_s.upcase)
80
+ Speed.const_get(unit.to_s.upcase)
80
81
  end
81
82
 
82
83
  def list_all
83
- (Distance.constants + Speed.constants).map { |c| c.downcase.to_sym }
84
+ format_list(Distance.constants + Speed.constants)
84
85
  end
85
86
 
86
87
  def list_speed
87
- Speed.constants.map { |c| c.downcase.to_sym }
88
+ format_list(Speed.constants)
88
89
  end
89
90
 
90
91
  def list_distance
91
- Distance.constants.map { |c| c.downcase.to_sym }
92
+ format_list(Distance.constants)
93
+ end
94
+
95
+ private
96
+
97
+ def format_unit(unit)
98
+ unit.downcase.gsub(' ', '_').to_sym
99
+ end
100
+
101
+ def format_list(constants)
102
+ constants.to_h { |c| [c.downcase.to_sym, c.to_s.gsub('_', ' ').gsub(' TO ', ' to ')] }
92
103
  end
93
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Calcpace
4
- VERSION = "1.5.5"
4
+ VERSION = '1.6.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calcpace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gilberto Saraiva
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Calcpace provides methods to calculate and convert values related to
13
13
  pace, distance, time, and speed. It supports various time formats and unit conversions.
@@ -20,6 +20,7 @@ files:
20
20
  - ".github/workflows/tests.yml"
21
21
  - ".gitignore"
22
22
  - ".ruby-version"
23
+ - ".tool-versions"
23
24
  - Gemfile
24
25
  - Gemfile.lock
25
26
  - README.md
@@ -51,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
54
  requirements: []
54
- rubygems_version: 3.6.2
55
+ rubygems_version: 3.6.7
55
56
  specification_version: 4
56
57
  summary: A Ruby gem for pace, distance, and time calculations.
57
58
  test_files: []