class GetParameters

Public Class Methods

new(argv = nil) click to toggle source
# File lib/calculate-tip/get-parameters.rb, line 5
def initialize(argv = nil)
        @argv = argv
        @param_amount = nil
        @param_tip = nil
        @currencie = nil
end

Public Instance Methods

get_parameters() click to toggle source
# 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