Class: GoldPrice::CLI
- Inherits:
-
Object
- Object
- GoldPrice::CLI
- Defined in:
- lib/gold_price/cli.rb
Overview
CLI Controller
Instance Attribute Summary collapse
-
#measurement ⇒ Object
Returns the value of attribute measurement.
-
#metal ⇒ Object
Returns the value of attribute metal.
Instance Method Summary collapse
Instance Attribute Details
#measurement ⇒ Object
Returns the value of attribute measurement.
4 5 6 |
# File 'lib/gold_price/cli.rb', line 4 def measurement @measurement end |
#metal ⇒ Object
Returns the value of attribute metal.
4 5 6 |
# File 'lib/gold_price/cli.rb', line 4 def end |
Instance Method Details
#call ⇒ Object
6 7 8 9 10 |
# File 'lib/gold_price/cli.rb', line 6 def call puts "Welcome to Gold Price!" puts "__*__" end |
#goodbye ⇒ Object
67 68 69 |
# File 'lib/gold_price/cli.rb', line 67 def goodbye puts "See you tomorrow! Stay Golden." end |
#measurement_menu ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gold_price/cli.rb', line 25 def 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." end price end |
#metal_menu ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gold_price/cli.rb', line 12 def 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" = gets.strip.to_i if < 1 || > 2 puts "Please enter a valid selection." end end |
#price ⇒ Object
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 == 1 && @measurement == 1 puts "Today the price of gold per gram is $#{gold_price.gold_by_gram} USD." puts "__*__" elsif == 1 && @measurement == 2 puts "Today the price of gold per ounce is $#{gold_price.gold_by_ounce} USD." puts "__*__" elsif == 2 && @measurement == 1 puts "Today the price of silver per gram is $#{silver_price.silver_by_gram} USD." puts "__*__" elsif == 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" else goodbye end end |