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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11e505136d4ec16df324d4600863b95cf05c876ab9f555d0491a6d25e5298373
4
- data.tar.gz: b48c77fa095fe0456d340718b8db42753b18eeab23f2ea1915aecb773c4bbbb4
3
+ metadata.gz: e7625bfcdb121b8adf89234b9b499dd3f034e185fc08ab8822906d81637310d3
4
+ data.tar.gz: f0b8b607203fa417b280ed7fca90cf7d4dcd870a5162297a97b0b99a89d091d4
5
5
  SHA512:
6
- metadata.gz: 42383fe5f022a230200106930675771999ca3fd694911dc661e383a29ed1df8317a80157a6b49f32463c4f8ec65d0e542f5cc6762160b96afc93a55d302e7729
7
- data.tar.gz: c9b98ab89f298a05601a3002062764435965487f53ab77c9f22c86b081fd78120ce62e49685165ef5dda9db014192d982d054e1744c9f48509b95080f3bc9d3b
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
- Please enter your example with space between each element (2 * 5).
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/[USERNAME]/calc_ruby_test_gem.
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PhazZzyo/calc_ruby_test_gem.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CalcRubyTestGem
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -3,29 +3,22 @@
3
3
  require_relative "calc_ruby_test_gem/version"
4
4
 
5
5
  module CalcRubyTestGem
6
- class Error < StandardError; end
6
+ class Error < StandardError;
7
+ end
7
8
 
8
- puts "Please enter your example with space between each element: "
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
- end
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.1.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-19 00:00:00.000000000 Z
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.