Complexify 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d963763b34a3cf23eddaec530e10c40ef7889ae
4
+ data.tar.gz: a19d8a3e8b5aa77b67d796c65ba716f793298ad1
5
+ SHA512:
6
+ metadata.gz: cc51503ca6c43709f72961063eced247e61a116cce3551346c396401ec89fd85e5582d3c352507a4438b41ba4336422df9f89b94440a923fb6ec3ba1a17c989f
7
+ data.tar.gz: 6c817df97aa5a6e4af08c05ee156d6c735106304303349aa6f3faa7f7390a59f5ecea6b90fe946bc4492ad657655116e695640dec924236752268e0c5d849c2c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,235 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ - "db/schema.rb"
5
+ - "bin/*"
6
+ - "config/environments/*"
7
+ UseCache: false
8
+ Style/CollectionMethods:
9
+ Description: Preferred collection methods.
10
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
11
+ Enabled: true
12
+ PreferredMethods:
13
+ collect: map
14
+ collect!: map!
15
+ find: detect
16
+ find_all: select
17
+ reduce: inject
18
+ Style/DotPosition:
19
+ Description: Checks the position of the dot in multi-line method calls.
20
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
21
+ Enabled: true
22
+ EnforcedStyle: trailing
23
+ SupportedStyles:
24
+ - leading
25
+ - trailing
26
+ Style/FileName:
27
+ Description: Use snake_case for source file names.
28
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
29
+ Enabled: false
30
+ Exclude: []
31
+ Style/GuardClause:
32
+ Description: Check for conditionals that can be replaced with guard clauses
33
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
34
+ Enabled: false
35
+ MinBodyLength: 1
36
+ Style/IfUnlessModifier:
37
+ Description: Favor modifier if/unless usage when you have a single-line body.
38
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
39
+ Enabled: false
40
+ MaxLineLength: 80
41
+ Style/OptionHash:
42
+ Description: Don't use option hashes when you can use keyword arguments.
43
+ Enabled: false
44
+ Style/PercentLiteralDelimiters:
45
+ Description: Use `%`-literal delimiters consistently
46
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
47
+ Enabled: false
48
+ PreferredDelimiters:
49
+ "%": "()"
50
+ "%i": "()"
51
+ "%q": "()"
52
+ "%Q": "()"
53
+ "%r": "{}"
54
+ "%s": "()"
55
+ "%w": "()"
56
+ "%W": "()"
57
+ "%x": "()"
58
+ Style/PredicateName:
59
+ Description: Check the names of predicate methods.
60
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
61
+ Enabled: true
62
+ NamePrefix:
63
+ - is_
64
+ - has_
65
+ - have_
66
+ NamePrefixBlacklist:
67
+ - is_
68
+ Exclude:
69
+ - spec/**/*
70
+ Style/RaiseArgs:
71
+ Description: Checks the arguments passed to raise/fail.
72
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
73
+ Enabled: false
74
+ EnforcedStyle: exploded
75
+ SupportedStyles:
76
+ - compact
77
+ - exploded
78
+ Style/SignalException:
79
+ Description: Checks for proper usage of fail and raise.
80
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
81
+ Enabled: false
82
+ EnforcedStyle: semantic
83
+ SupportedStyles:
84
+ - only_raise
85
+ - only_fail
86
+ - semantic
87
+ Style/SingleLineBlockParams:
88
+ Description: Enforces the names of some block params.
89
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
90
+ Enabled: false
91
+ Methods:
92
+ - reduce:
93
+ - a
94
+ - e
95
+ - inject:
96
+ - a
97
+ - e
98
+ Style/SingleLineMethods:
99
+ Description: Avoid single-line methods.
100
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
101
+ Enabled: false
102
+ AllowIfMethodIsEmpty: true
103
+ Style/StringLiterals:
104
+ Description: Checks if uses of quotes match the configured preference.
105
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
106
+ Enabled: true
107
+ EnforcedStyle: double_quotes
108
+ SupportedStyles:
109
+ - single_quotes
110
+ - double_quotes
111
+ Style/StringLiteralsInInterpolation:
112
+ Description: Checks if uses of quotes inside expressions in interpolated strings
113
+ match the configured preference.
114
+ Enabled: true
115
+ EnforcedStyle: single_quotes
116
+ SupportedStyles:
117
+ - single_quotes
118
+ - double_quotes
119
+ Style/TrailingCommaInArguments:
120
+ Description: Checks for trailing comma in parameter lists and literals.
121
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
122
+ Enabled: false
123
+ EnforcedStyleForMultiline: no_comma
124
+ SupportedStyles:
125
+ - comma
126
+ - no_comma
127
+ Metrics/AbcSize:
128
+ Description: A calculated magnitude based on number of assignments, branches, and
129
+ conditions.
130
+ Enabled: false
131
+ Max: 15
132
+ Metrics/ClassLength:
133
+ Description: Avoid classes longer than 100 lines of code.
134
+ Enabled: false
135
+ CountComments: false
136
+ Max: 100
137
+ Metrics/ModuleLength:
138
+ CountComments: false
139
+ Max: 100
140
+ Description: Avoid modules longer than 100 lines of code.
141
+ Enabled: false
142
+ Metrics/CyclomaticComplexity:
143
+ Description: A complexity metric that is strongly correlated to the number of test
144
+ cases needed to validate a method.
145
+ Enabled: false
146
+ Max: 6
147
+ Metrics/MethodLength:
148
+ Description: Avoid methods longer than 10 lines of code.
149
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
150
+ Enabled: false
151
+ CountComments: false
152
+ Max: 10
153
+ Metrics/ParameterLists:
154
+ Description: Avoid parameter lists longer than three or four parameters.
155
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
156
+ Enabled: false
157
+ Max: 5
158
+ CountKeywordArgs: true
159
+ Metrics/PerceivedComplexity:
160
+ Description: A complexity metric geared towards measuring complexity for a human
161
+ reader.
162
+ Enabled: false
163
+ Max: 7
164
+ Lint/AssignmentInCondition:
165
+ Description: Don't use assignment in conditions.
166
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
167
+ Enabled: false
168
+ AllowSafeAssignment: true
169
+ Style/InlineComment:
170
+ Description: Avoid inline comments.
171
+ Enabled: false
172
+ Style/AccessorMethodName:
173
+ Description: Check the naming of accessor methods for get_/set_.
174
+ Enabled: false
175
+ Style/Alias:
176
+ Description: Use alias_method instead of alias.
177
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
178
+ Enabled: false
179
+ Style/Documentation:
180
+ Description: Document classes and non-namespace modules.
181
+ Enabled: false
182
+ Style/DoubleNegation:
183
+ Description: Checks for uses of double negation (!!).
184
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
185
+ Enabled: false
186
+ Style/EachWithObject:
187
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
188
+ Enabled: false
189
+ Style/EmptyLiteral:
190
+ Description: Prefer literals to Array.new/Hash.new/String.new.
191
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
192
+ Enabled: false
193
+ Style/ModuleFunction:
194
+ Description: Checks for usage of `extend self` in modules.
195
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
196
+ Enabled: false
197
+ Style/OneLineConditional:
198
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
199
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
200
+ Enabled: false
201
+ Style/PerlBackrefs:
202
+ Description: Avoid Perl-style regex back references.
203
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
204
+ Enabled: false
205
+ Style/Send:
206
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
207
+ may overlap with existing methods.
208
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
209
+ Enabled: false
210
+ Style/SpecialGlobalVars:
211
+ Description: Avoid Perl-style global variables.
212
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
213
+ Enabled: false
214
+ Style/VariableInterpolation:
215
+ Description: Don't interpolate global, instance and class variables directly in
216
+ strings.
217
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
218
+ Enabled: false
219
+ Style/WhenThen:
220
+ Description: Use when x then ... for one-line cases.
221
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
222
+ Enabled: false
223
+ Lint/EachWithObjectArgument:
224
+ Description: Check for immutable argument given to each_with_object.
225
+ Enabled: true
226
+ Lint/HandleExceptions:
227
+ Description: Don't suppress exception.
228
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
229
+ Enabled: false
230
+ Lint/LiteralInCondition:
231
+ Description: Checks of literals used in conditions.
232
+ Enabled: false
233
+ Lint/LiteralInInterpolation:
234
+ Description: Checks for literals used in interpolation.
235
+ Enabled: false
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at lovelynisrael@hotmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "Complexify/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Complexify"
8
+ spec.version = Complexify::VERSION
9
+ spec.authors = ["Lovelyn"]
10
+ spec.email = ["lovelynisrael@hotmail.com"]
11
+
12
+ spec.summary = "A Complex Number Library built with Ruby"
13
+ spec.description = "Performs basic Mathematical Operations on Complex Numbers"
14
+ spec.homepage = "https://github.com/Amoralyn/Complexify"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect"\
23
+ "against public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.11"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in Complexify.gemspec
4
+ gem "rspec"
5
+ gem "pry"
6
+ gem 'pry-nav'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Lovelyn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Complexify
2
+
3
+ Welcome to Complexify! Complexify is a Complex Number Library that allows you to perform the basic mathematical operation on two or more Complex Numbers.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'Complexify'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install Complexify
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Amoralyn/Complexify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
35
+
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
41
+ ## Copyright
42
+
43
+ This gem is a property of Lovelyn Tijesunimi-Israel.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Complexify"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require "Complexify/version"
2
+
3
+ module Complexify
4
+ end
@@ -0,0 +1,72 @@
1
+ module Math
2
+ module Complexify
3
+ class Complex
4
+ attr_accessor :real
5
+ attr_accessor :imaginary
6
+ def initialize(real, imaginary)
7
+ # when Math::Complexify.new is called, initialize
8
+ # is run after the object is instantiated
9
+ @real = real
10
+ @imaginary = imaginary
11
+ end
12
+
13
+ def addition(z)
14
+ # adds the real part of z to the real part of the calling method
15
+ # also adds the imaginary parts and returs the result
16
+ Math::Complexify::Complex.new(@real + z.real, @imaginary + z.imaginary)
17
+ end
18
+
19
+ def subtraction(z)
20
+ # adds the real part of z to the real part of the calling method
21
+ # also adds the imaginary parts of the calling method
22
+ Math::Complexify::Complex.new(@real - z.real, @imaginary - z.imaginary)
23
+ end
24
+
25
+ def multiplication(z)
26
+ z = complex_checker(z)
27
+ n_real = (@real * z.real) - (@imaginary * z.imaginary)
28
+ n_imag = (@real * z.imaginary) + (@imaginary * z.real)
29
+ Math::Complexify::Complex.new(n_real, n_imag).to_s
30
+ end
31
+
32
+ def division(z)
33
+ z = complex_checker(z)
34
+ coef = (z.imaginary**2 + z.real**2).to_f
35
+ n_real = (@imaginary * z.imaginary + @real * z.real) / coef
36
+ n_imag = (-@real * z.imaginary + @imaginary * z.real) / coef
37
+ Math::Complexify::Complex.new(n_real, n_imag).to_s
38
+ end
39
+
40
+ def complex_checker(z)
41
+ if z.is_a? Math::Complexify::Complex
42
+ # do nothing if the argument is already of type Complex!
43
+ return z
44
+ else
45
+ # else, make it a type Complex and make its imaginary part = 0
46
+ return Math::Complexify::Complex.new(z, 0)
47
+ end
48
+ end
49
+
50
+ def to_s
51
+ # the to_s function outputs a string automatically, for example:
52
+ # suppose z is an object of type complex Number, then
53
+ # puts z will implicitly call z.to_s and then output the result
54
+ output = if @imaginary == 0
55
+ @real.to_s
56
+ elsif @real == 0
57
+ "#{@imaginary}i"
58
+ elsif @imaginary == 1
59
+ "#{@real} + i"
60
+ elsif @imaginary > 1
61
+ "#{@real} + #{@imaginary}i"
62
+ elsif @imaginary == -1
63
+ "#{@real} - i"
64
+ else
65
+ "#{@real} - #{ -1 * @imaginary}i"
66
+ end
67
+ output
68
+ end
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,3 @@
1
+ module Complexify
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,176 @@
1
+ require_relative "Complexify/complex_num"
2
+ require "colorize"
3
+
4
+ class StartApp
5
+ def start
6
+ puts "\n\n Welcome to Complexify!!!".green
7
+ puts "\n\n What is Complexify ".green
8
+ puts "\n Complexify is a Complex Number Library that".red
9
+ puts "\n helps you perform basic mathematical operations".red
10
+ puts "\n on Complex Numbers.".red
11
+ puts "\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
12
+ puts "\n At any point in the program, use CTRL-C to end the program".red
13
+ puts "\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
14
+
15
+ @result = []
16
+ get_operation_type
17
+ # operation_guide
18
+ end
19
+
20
+ def get_operation_type
21
+ puts "\n Will you be performing a Single or Multiple Operation?".green
22
+ puts "\n Enter 'S' or 'Single' for Single or"\
23
+ " 'M' or 'multiple' for Multiple".blue
24
+ op_type = gets.chomp.downcase
25
+ if op_type == "s" || op_type == "single"
26
+ get_copmlex_num_single
27
+ elsif op_type == "m" || op_type == "multiple"
28
+ puts "\n How many operands will you be using?".green
29
+ get_complex_num_multiple
30
+ else
31
+ puts "Enter a valid option"
32
+ get_operation_type
33
+ end
34
+ end
35
+
36
+ def get_copmlex_num_single
37
+ 2.times do |i|
38
+ position = case i + 1
39
+ when 1
40
+ "1st"
41
+ else
42
+ "2nd"
43
+ end
44
+
45
+ puts "\n Enter the real part of your #{position}"\
46
+ " complex number".yellow
47
+ real = gets.chomp.to_i
48
+ puts "\n Enter the imaginary part of your #{position}"\
49
+ " complex number".yellow
50
+ imaginary = gets.chomp.to_i
51
+ # require "pry"; binding.pry
52
+ @result.push(Math::Complexify::Complex.new(real, imaginary))
53
+ puts "\n Your #{position} complex number is #{@result[i]} "
54
+ end
55
+ operation_guide
56
+ operation
57
+ # operation_guide
58
+ end
59
+
60
+ def get_complex_num_multiple
61
+ loop do
62
+ operand_num = gets.chomp.to_i
63
+ if operand_num > 2
64
+ count = 1
65
+ operand_num.times do |i|
66
+ position = case i + 1
67
+ when 1
68
+ "1st"
69
+ when 2
70
+ "2nd"
71
+ when 3
72
+ "3rd"
73
+ else
74
+ "#{count}th"
75
+ end
76
+
77
+ puts "Enter the real part of your #{position}"\
78
+ " complex number".yellow
79
+ real = gets.chomp.to_i
80
+ puts "Enter the Imaginary part of your #{position}"\
81
+ " complex number".yellow
82
+ imaginary = gets.chomp.to_i
83
+ @result.push(Math::Complexify::Complex.new(real, imaginary))
84
+ puts "Your #{position} complex number is #{@result[i]} "
85
+ # operation_guide
86
+ # operation
87
+ count += 1
88
+ end
89
+ # break
90
+ elsif operand_num == 2
91
+ puts "This is a Single operation".blue
92
+ get_operation_type
93
+ else
94
+ puts "You cannot have #{operand_num} operand".red
95
+ get_operation_type
96
+ end
97
+ break
98
+ end
99
+ operation_guide
100
+ operation
101
+ # operation_guide
102
+ end
103
+
104
+ def operation_guide
105
+ puts "\n\nOPERATORS: \n\n".blue
106
+ puts "** To add enter, 'ADD'**".blue
107
+ puts "** To subtract, enter 'SUBTRACT' **".blue
108
+ puts "** To multiply, enter 'MULTIPLY' **".blue
109
+ puts "** To divide, enter 'DIVIDE' **".blue
110
+ puts "** To exit, enter 'EXIT' **".blue
111
+ end
112
+
113
+ def operation
114
+ @result.each do |ech|
115
+ complex_num_count = @result.index(ech)
116
+ count = 1 + @result.index(ech)
117
+ break if count >= @result.length
118
+ # operation_guide
119
+ user_choice = gets.chomp.upcase
120
+
121
+ if complex_num_count == 0 && count == 1
122
+ case user_choice
123
+ when "ADD"
124
+ puts "#{@result[0]} + #{@result[1]} is :\n\n"
125
+ @temp = @result[0].addition(@result[1])
126
+ puts @temp
127
+ when "SUBTRACT"
128
+ puts "#{@result[0]} - #{@result[1]} is :\n\n"
129
+ @temp = @result[0].subtraction(@result[1])
130
+ puts @temp
131
+ when "MULTIPLY"
132
+ puts "#{@result[0]} * #{@result[1]} is :\n\n"
133
+ @temp = @result[0].multiplication(@result[1])
134
+ puts @temp
135
+ when "DIVIDE"
136
+ puts "#{@result[0]} / #{@result[1]} is :\n\n"
137
+ @temp = @result[0].division(@result[1])
138
+ puts @temp
139
+ when "EXIT"
140
+ break
141
+ else
142
+ puts "Enter a valid Operator".red
143
+ redo
144
+ operation_guide
145
+ end
146
+ else
147
+ case user_choice
148
+ when "ADD"
149
+ puts "#{@temp} + #{@result[count]} is :\n\n"
150
+ @temp = @temp.addition(@result[count])
151
+ puts @temp
152
+ when "SUBTRACT"
153
+ puts "#{@temp} - #{@result[count]} is :\n\n"
154
+ @temp = @temp.subtraction(@result[count])
155
+ puts @temp
156
+ when "MULTIPLY"
157
+ puts "#{@temp} * #{@result[count]} is :\n\n"
158
+ @temp = @temp.multiplication(@result[count])
159
+ puts @temp
160
+ when "DIVIDE"
161
+ puts "#{@temp} / #{@result[count]} is :\n\n"
162
+ @temp = @temp.division(@result[count])
163
+ puts @temp
164
+ when "EXIT"
165
+ break
166
+ else
167
+ puts "Enter a valid Operator".red
168
+ redo
169
+ end
170
+ end
171
+ # end
172
+ end
173
+ end
174
+ end
175
+
176
+ StartApp.new.start
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Complexify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lovelyn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Performs basic Mathematical Operations on Complex Numbers
56
+ email:
57
+ - lovelynisrael@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Complexify.gemspec
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/Complexify.rb
75
+ - lib/Complexify/complex_num.rb
76
+ - lib/Complexify/version.rb
77
+ - lib/Complexify_init.rb
78
+ homepage: https://github.com/Amoralyn/Complexify
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ allowed_push_host: https://rubygems.org
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: A Complex Number Library built with Ruby
103
+ test_files: []
104
+ has_rdoc: