Class: GetParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/calculate-tip/get-parameters.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv = nil) ⇒ GetParameters

Returns a new instance of GetParameters.



5
6
7
8
9
10
# File 'lib/calculate-tip/get-parameters.rb', line 5

def initialize(argv = nil)
	@argv = argv
	@param_amount = nil
	@param_tip = nil
	@currencie = nil
end

Instance Method Details

#get_parametersObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/calculate-tip/get-parameters.rb', line 12

def get_parameters
	data_json = JSON.parse( IO.read("lib/calculate-tip/currencies.json") ) 
	temp_currencie = nil
	
	if not @argv.empty?
		@param_amount = @argv[1]
		if data_json.has_key? @argv[2].upcase
			@param_tip = @argv[4]
		else
			@param_tip = @argv[3]
		end	
		temp_currencie = @argv[2]
	else
		puts "Please provide amount: "
		param_arg = gets.chomp
		param_arg = param_arg.split(/\s+/)
		@param_amount = param_arg[0]
		temp_currencie = param_arg[1]			
		puts "Please provide tip (%): "
		@param_tip = gets.chomp
	end

	if @param_tip.nil? or @param_tip.empty?
		@param_tip = 15.0
	end 

	if not temp_currencie.nil? and data_json.has_key? temp_currencie.upcase
		@currencie = temp_currencie
	end

	return @param_amount, @param_tip, @currencie
end