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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daccb759c2490fb12685cb0ad2de29c98a9dd36326b431a8a560a6fe3b9ecc04
4
- data.tar.gz: f7ebbbba7698dbd9b6b175f5276aecea37f6606e9481a6bec62d644f2fe481ab
3
+ metadata.gz: 9fbb08ae17c873d2d0297b1fb9ad069f8384a29d8486f9d1a5f815e06baa41ff
4
+ data.tar.gz: 50d06764bdb2c19977f07609be74e807be044d503a6fff488522f322a3bb9bd9
5
5
  SHA512:
6
- metadata.gz: 2313a6c7d475a227769d7fed92dcc5b6053855f18a9d33998928341478018767e3ba1633272a10fb68746c3c4a1954b7243aa113508bd7f00d25bc208ed2b0b4
7
- data.tar.gz: 92f9a1a5f1d8949ad289b641da16a4a637a776bbe916fec52a9299c116d751a73aaa7d66e1ed9589ffd3541e588fb3f5acd0058d4e324d1c91cd537e5bed3414
6
+ metadata.gz: 57e61daf4dcabe54dc04bea0c9919022199f68ec309928133626de468ddc4ce7e7fc92a77592763442c2e1ce98b6bdf8e2d67c583ed877290557e368b9eda49f
7
+ data.tar.gz: 9f18cb76258daadeeb6b28a49d02e8f5b37cabb687706c5fd5327a94371dc9296a0e6f053db03f4d9b6751daa599e584ef200a3c016134d48755b9bdcfec9baf
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2021-04-26
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Converty
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.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-27 00:00:00.000000000 Z
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