converty 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +14 -1
- data/exe/converty +42 -0
- data/lib/converty.rb +4 -0
- data/lib/converty/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fbb08ae17c873d2d0297b1fb9ad069f8384a29d8486f9d1a5f815e06baa41ff
|
4
|
+
data.tar.gz: 50d06764bdb2c19977f07609be74e807be044d503a6fff488522f322a3bb9bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57e61daf4dcabe54dc04bea0c9919022199f68ec309928133626de468ddc4ce7e7fc92a77592763442c2e1ce98b6bdf8e2d67c583ed877290557e368b9eda49f
|
7
|
+
data.tar.gz: 9f18cb76258daadeeb6b28a49d02e8f5b37cabb687706c5fd5327a94371dc9296a0e6f053db03f4d9b6751daa599e584ef200a3c016134d48755b9bdcfec9baf
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.2.0] - 2021-04-28
|
4
|
+
|
5
|
+
- Add `converty` CLI executable
|
6
|
+
|
7
|
+
## [0.1.0] - 2021-04-27
|
4
8
|
|
5
9
|
- Initial release
|
10
|
+
- Includes rudimentary conversion for the following units:
|
11
|
+
- Distance
|
12
|
+
- Feet (ft)
|
13
|
+
- Inches (in)
|
14
|
+
- Miles (mi)
|
15
|
+
- Kilometers (km)
|
16
|
+
- Weight
|
17
|
+
- Ounces (oz)
|
18
|
+
- Pounds (lb)
|
data/exe/converty
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../lib/converty"
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
args = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Convert between different units of the same measurement type\n\nUsage: converty 5 --from km --to mi [options]"
|
10
|
+
|
11
|
+
opts.on("-f", "--from UNIT", "The unit to convert from")
|
12
|
+
opts.on("-t", "--to UNIT", "The unit to convert to, must be the same measurement type as the from arg")
|
13
|
+
opts.on("-r", "--round DECIMAL_PLACES", "How many decimal places to round to")
|
14
|
+
end.parse!(into: args)
|
15
|
+
|
16
|
+
amount = ARGV[0]
|
17
|
+
|
18
|
+
errors = []
|
19
|
+
|
20
|
+
if amount.nil?
|
21
|
+
errors.push("amount arg is required")
|
22
|
+
end
|
23
|
+
|
24
|
+
if args[:to].nil?
|
25
|
+
errors.push("--to arg is required")
|
26
|
+
end
|
27
|
+
|
28
|
+
if args[:from].nil?
|
29
|
+
errors.push("--from arg is required")
|
30
|
+
end
|
31
|
+
|
32
|
+
if errors.any?
|
33
|
+
raise errors.join(", ")
|
34
|
+
end
|
35
|
+
|
36
|
+
amount = Converty.convert(amount, from: args[:from], to: args[:to])
|
37
|
+
|
38
|
+
if round = args[:round]
|
39
|
+
amount = amount.round(round.to_i)
|
40
|
+
end
|
41
|
+
|
42
|
+
puts amount
|
data/lib/converty.rb
CHANGED
@@ -67,6 +67,10 @@ module Converty
|
|
67
67
|
# Converty.convert(5, from: :km, to: :mi).round(1) => 3.1
|
68
68
|
# Converty.convert(16, from: :oz, to: :lb) => 1.0
|
69
69
|
def self.convert(amount, from:, to:)
|
70
|
+
amount = amount.to_f
|
71
|
+
from = from.to_sym
|
72
|
+
to = to.to_sym
|
73
|
+
|
70
74
|
to_unit = UNITS[to]
|
71
75
|
from_unit = UNITS[from]
|
72
76
|
|
data/lib/converty/version.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: converty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Chalupa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Require the Converty class and pass in a numerical value and the from and to units
|
15
15
|
to easily convert a number between different measurement systems. Currently supports distance and weight.
|
16
16
|
email:
|
17
17
|
- brett@monoso.co
|
18
|
-
executables:
|
18
|
+
executables:
|
19
|
+
- converty
|
19
20
|
extensions: []
|
20
21
|
extra_rdoc_files: []
|
21
22
|
files:
|
@@ -33,6 +34,7 @@ files:
|
|
33
34
|
- bin/console
|
34
35
|
- bin/setup
|
35
36
|
- converty.gemspec
|
37
|
+
- exe/converty
|
36
38
|
- lib/converty.rb
|
37
39
|
- lib/converty/version.rb
|
38
40
|
homepage: https://github.com/monoso/converty
|