calc_ruby_test_gem 0.1.0 → 0.2.2

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: 3ad09f44faa67b75bcd5507365604bfdb321397b13a0e8baa1fbadb4e777c9d4
4
+ data.tar.gz: b7ef8708f0624f0d60aabe3435398de7be7b5e365cc47005a56c0303afd29aed
5
5
  SHA512:
6
- metadata.gz: 42383fe5f022a230200106930675771999ca3fd694911dc661e383a29ed1df8317a80157a6b49f32463c4f8ec65d0e542f5cc6762160b96afc93a55d302e7729
7
- data.tar.gz: c9b98ab89f298a05601a3002062764435965487f53ab77c9f22c86b081fd78120ce62e49685165ef5dda9db014192d982d054e1744c9f48509b95080f3bc9d3b
6
+ metadata.gz: 80bcb0f63fbb146bf57f05565d54f3a52244baf1a1c2a957cf16b2d3b395da3a46d647c14c7f209e974eeb20209b19a0544457ee17f5fddcf6dfd36423724a5a
7
+ data.tar.gz: 1312cc424a43fea0d0f98ae77eb58a5d90c81cb8c9a33368d9bd0bf327fbc54eb837123b01dde4806fa9d109435a92cd0019bf10389b9b539424f86d5f970c39
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ calc_ruby_test_gem (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (13.0.6)
10
+
11
+ PLATFORMS
12
+ x86_64-linux
13
+
14
+ DEPENDENCIES
15
+ calc_ruby_test_gem!
16
+ rake (~> 13.0)
17
+
18
+ BUNDLED WITH
19
+ 2.3.24
data/README.md CHANGED
@@ -14,7 +14,14 @@ 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
+ # Now you can pass examples in that sequance: (first_operand, second_operand, "operation")
21
+ CalcRubyTestGem::calculate(1,2,"+")
22
+ => "1 + 2 = 3"
23
+ CalcRubyTestGem::calculate(1,2,"-")
24
+ => "1 - 2 = -1"
18
25
 
19
26
  ## Development
20
27
 
@@ -24,4 +31,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
24
31
 
25
32
  ## Contributing
26
33
 
27
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/calc_ruby_test_gem.
34
+ 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.2"
5
5
  end
@@ -3,29 +3,21 @@
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
+ rescue ZeroDivisionError => e
20
+ "Division by zero is not allowed."
21
+ end
22
+ end
23
+ 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.2
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.
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - Gemfile
22
+ - Gemfile.lock
22
23
  - README.md
23
24
  - Rakefile
24
25
  - calc_ruby_test_gem.gemspec