calc_ruby_test_gem 0.1.0 → 0.2.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 +4 -4
- data/README.md +7 -2
- data/lib/calc_ruby_test_gem/version.rb +1 -1
- data/lib/calc_ruby_test_gem.rb +17 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7625bfcdb121b8adf89234b9b499dd3f034e185fc08ab8822906d81637310d3
|
4
|
+
data.tar.gz: f0b8b607203fa417b280ed7fca90cf7d4dcd870a5162297a97b0b99a89d091d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db2d5c9623faf1a48129cbdb78e4f8ced2eb38cf72293e5576d12d6e5fbdc02296d5a45944d879d6375cda84e0a69eb663ab03af404effcaa21cd5a7e9a91566
|
7
|
+
data.tar.gz: 149a6c45debbdd652b1fba19c3546f74bf333043752344d9d44d9a6f8a24b3e872168676d7c843c70bfc56c26a11fdb6d69edee985c0781d9baa93d63307a473
|
data/README.md
CHANGED
@@ -14,7 +14,12 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
-
|
17
|
+
To test the calculator through irb:
|
18
|
+
# Launch IRB and load this file calc_ruby_test_gem.rb
|
19
|
+
irb -r ./lib/calc_ruby_test_gem
|
20
|
+
# Then start a module
|
21
|
+
CalcRubyTestGem
|
22
|
+
# Done! Now you can pass examples.
|
18
23
|
|
19
24
|
## Development
|
20
25
|
|
@@ -24,4 +29,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
24
29
|
|
25
30
|
## Contributing
|
26
31
|
|
27
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/PhazZzyo/calc_ruby_test_gem.
|
data/lib/calc_ruby_test_gem.rb
CHANGED
@@ -3,29 +3,22 @@
|
|
3
3
|
require_relative "calc_ruby_test_gem/version"
|
4
4
|
|
5
5
|
module CalcRubyTestGem
|
6
|
-
class Error < StandardError;
|
6
|
+
class Error < StandardError;
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
example = gets.to_s.split
|
11
|
-
|
12
|
-
a = example[0].to_f
|
13
|
-
b = example[1].to_s
|
14
|
-
c = example[2].to_f
|
15
|
-
|
16
|
-
case b
|
17
|
-
when "+"
|
18
|
-
puts "The result is: #{a + c}"
|
19
|
-
|
20
|
-
when "-"
|
21
|
-
puts "The result is: #{a - c}"
|
22
|
-
|
23
|
-
when "*"
|
24
|
-
puts "The result is: #{a * c}"
|
25
|
-
|
26
|
-
when "/"
|
27
|
-
puts "The result is: #{a / c}"
|
28
|
-
else
|
29
|
-
puts "Sorry, you entered an invalid operator, only +, -, *, / are allowed!"
|
9
|
+
class UnsupportedOperation < StandardError
|
30
10
|
end
|
31
|
-
|
11
|
+
|
12
|
+
ALLOWED_OPERATIONS = ['+', '-', '/', '*'].freeze
|
13
|
+
def self.calculate(first_operand, second_operand, operation)
|
14
|
+
raise ArgumentError if first_operand.class == String || second_operand.class == String
|
15
|
+
raise UnsupportedOperation unless ALLOWED_OPERATIONS.include? operation
|
16
|
+
|
17
|
+
begin
|
18
|
+
"#{first_operand} #{operation} #{second_operand} = #{first_operand.send(operation, second_operand)}"
|
19
|
+
puts "Test"
|
20
|
+
rescue ZeroDivisionError => e
|
21
|
+
"Division by zero is not allowed."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calc_ruby_test_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Basic calculator with addition, subtraction, multiplication and division
|
14
14
|
mathematical calculations.
|