Class: StartApp

Inherits:
Object
  • Object
show all
Defined in:
lib/Complexify_init.rb

Instance Method Summary collapse

Instance Method Details

#get_complex_num_multipleObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/Complexify_init.rb', line 60

def get_complex_num_multiple
  loop do
    operand_num = gets.chomp.to_i
    if operand_num > 2
      count = 1
      operand_num.times do |i|
        position = case i + 1
                   when 1
                     "1st"
                   when 2
                     "2nd"
                   when 3
                     "3rd"
                   else
                     "#{count}th"
                   end

        puts "Enter the real part of your #{position}"\
             " complex number".yellow
        real = gets.chomp.to_i
        puts "Enter the Imaginary part of your #{position}"\
             " complex number".yellow
        imaginary = gets.chomp.to_i
        @result.push(Math::Complexify::Complex.new(real, imaginary))
        puts "Your #{position} complex number is #{@result[i]} "
        # operation_guide
        # operation
        count += 1
      end
      # break
    elsif operand_num == 2
      puts "This is a Single operation".blue
      get_operation_type
    else
      puts "You cannot have #{operand_num} operand".red
      get_operation_type
    end
    break
  end
  operation_guide
  operation
  # operation_guide
end

#get_copmlex_num_singleObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/Complexify_init.rb', line 36

def get_copmlex_num_single
  2.times do |i|
    position = case i + 1
               when 1
                 "1st"
               else
                 "2nd"
               end

    puts "\n Enter the real part of your #{position}"\
         " complex number".yellow
    real = gets.chomp.to_i
    puts "\n Enter the imaginary part of your #{position}"\
         " complex number".yellow
    imaginary = gets.chomp.to_i
      # require "pry"; binding.pry
    @result.push(Math::Complexify::Complex.new(real, imaginary))
    puts "\n Your #{position} complex number is #{@result[i]} "
  end
  operation_guide
  operation
  # operation_guide
end

#get_operation_typeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/Complexify_init.rb', line 20

def get_operation_type
  puts "\n Will you be performing a Single or Multiple Operation?".green
  puts "\n Enter 'S' or 'Single' for Single or"\
       " 'M' or 'multiple' for Multiple".blue
  op_type = gets.chomp.downcase
  if op_type == "s" || op_type == "single"
    get_copmlex_num_single
  elsif op_type == "m" || op_type == "multiple"
    puts "\n How many operands will you be using?".green
    get_complex_num_multiple
  else
    puts "Enter a valid option"
    get_operation_type
  end
end

#operationObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/Complexify_init.rb', line 113

def operation
    @result.each do |ech|
      complex_num_count = @result.index(ech)
      count = 1 + @result.index(ech)
      break if count >= @result.length
      # operation_guide
      user_choice = gets.chomp.upcase

      if complex_num_count == 0 && count == 1
        case user_choice
        when "ADD"
          puts "#{@result[0]}  +  #{@result[1]} is :\n\n"
          @temp = @result[0].addition(@result[1])
          puts @temp
        when "SUBTRACT"
          puts "#{@result[0]}  -  #{@result[1]} is :\n\n"
          @temp = @result[0].subtraction(@result[1])
          puts @temp
        when "MULTIPLY"
          puts "#{@result[0]}  *  #{@result[1]} is :\n\n"
          @temp = @result[0].multiplication(@result[1])
          puts @temp
        when "DIVIDE"
          puts "#{@result[0]}  /  #{@result[1]} is :\n\n"
          @temp = @result[0].division(@result[1])
          puts @temp
        when "EXIT"
          break
        else
          puts "Enter a valid Operator".red
          redo
          operation_guide
        end
      else
        case user_choice
        when "ADD"
          puts "#{@temp}  +  #{@result[count]} is :\n\n"
          @temp = @temp.addition(@result[count])
          puts @temp
        when "SUBTRACT"
          puts "#{@temp}  -  #{@result[count]} is :\n\n"
          @temp = @temp.subtraction(@result[count])
          puts @temp
        when "MULTIPLY"
          puts "#{@temp}  *  #{@result[count]} is :\n\n"
          @temp = @temp.multiplication(@result[count])
          puts @temp
        when "DIVIDE"
          puts "#{@temp}  /  #{@result[count]} is :\n\n"
          @temp = @temp.division(@result[count])
          puts @temp
        when "EXIT"
          break
        else
          puts "Enter a valid Operator".red
          redo
        end
      end
    # end
  end
end

#operation_guideObject



104
105
106
107
108
109
110
111
# File 'lib/Complexify_init.rb', line 104

def operation_guide
  puts "\n\nOPERATORS: \n\n".blue
  puts "** To add enter, 'ADD'**".blue
  puts "** To subtract, enter 'SUBTRACT' **".blue
  puts "** To multiply, enter 'MULTIPLY' **".blue
  puts "** To divide, enter 'DIVIDE' **".blue
  puts "** To exit, enter 'EXIT' **".blue
end

#startObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/Complexify_init.rb', line 5

def start
  puts "\n\n Welcome to Complexify!!!".green
  puts "\n\n What is Complexify ".green
  puts "\n Complexify is a Complex Number Library that".red
  puts "\n helps you perform basic mathematical operations".red
  puts "\n on Complex Numbers.".red
  puts "\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  puts "\n At any point in the program, use CTRL-C to end the program".red
  puts "\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

  @result = []
  get_operation_type
  # operation_guide
end