Class: GoldPrice::CLI

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

Overview

CLI Controller

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#measurementObject

Returns the value of attribute measurement.



4
5
6
# File 'lib/gold_price/cli.rb', line 4

def measurement
  @measurement
end

#metalObject

Returns the value of attribute metal.



4
5
6
# File 'lib/gold_price/cli.rb', line 4

def metal
  @metal
end

Instance Method Details

#callObject



6
7
8
9
10
# File 'lib/gold_price/cli.rb', line 6

def call
  puts "Welcome to Gold Price!"
  puts "__*__"
  metal_menu
end

#goodbyeObject



67
68
69
# File 'lib/gold_price/cli.rb', line 67

def goodbye
  puts "See you tomorrow! Stay Golden."
end

#measurement_menuObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gold_price/cli.rb', line 25

def measurement_menu
  puts "Please enter the number of the measurement you would like to use and press enter:"
  puts "1. Grams"
  puts "2. Ounces"
  @measurement = gets.strip.to_i

  if @measurement < 1 || @measurement > 2
    puts "Please enter a valid selection."
    measurement_menu
  end
  price
end

#metal_menuObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gold_price/cli.rb', line 12

def metal_menu
  puts "Please enter the number of the metal you would like to see the price of and press enter:"
  puts "1. Gold"
  puts "2. Silver"
  @metal = gets.strip.to_i

  if @metal < 1 || @metal > 2
    puts "Please enter a valid selection."
    metal_menu
  end
  measurement_menu
end

#priceObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gold_price/cli.rb', line 38

def price
  @silver_prices = GoldPrice::Price.silver_prices
  @gold_prices = GoldPrice::Price.gold_prices
  silver_price = @silver_prices[0]
  gold_price = @gold_prices[0]
    if @metal == 1 && @measurement == 1
      puts "Today the price of gold per gram is $#{gold_price.gold_by_gram} USD."
      puts "__*__"
    elsif @metal == 1 && @measurement == 2
      puts "Today the price of gold per ounce is $#{gold_price.gold_by_ounce} USD."
      puts "__*__"
    elsif @metal == 2 && @measurement == 1
      puts "Today the price of silver per gram is $#{silver_price.silver_by_gram} USD."
      puts "__*__"
    elsif @metal == 2 && @measurement == 2
      puts "Today the price of silver per ounce is $#{silver_price.silver_by_ounce} USD."
      puts "__*__"
    end


  puts "Would you like to see another price?"
  input = gets.strip.upcase
  if input == "Y" || input == "YES"
    metal_menu
  else
    goodbye
  end
end