# frozen_string_literal: true module Cryptum # This module is used to Accept User Input at Session Initiation module Option # Common module to validate input submitted at session initiation module InputValidation # Validate Options for cryptum Driver public_class_method def self.check(opts = {}) option_choice = opts[:option_choice] # Conditions to display cryptum usage if option_choice.symbol.nil? && option_choice.list_products.nil? usage = true reason = :symbol end option_choice.session_root = "#{Dir.home}/cryptum" if option_choice.session_root.nil? unless Dir.exist?(option_choice.session_root) usage = true reason = :session_root end option_choice.market_trend_reset = '1D' if option_choice.market_trend_reset.nil? case option_choice.market_trend_reset when '1W' option_choice.market_trend_reset_label = '1W' option_choice.market_trend_reset = 604_800 when '1D' option_choice.market_trend_reset_label = '1D' option_choice.market_trend_reset = 86_400 when '4h' option_choice.market_trend_reset_label = '4h' option_choice.market_trend_reset = 14_400 when '3h' option_choice.market_trend_reset_label = '3h' option_choice.market_trend_reset = 10_800 when '2h' option_choice.market_trend_reset_label = '2h' option_choice.market_trend_reset = 7_200 when '1h' option_choice.market_trend_reset_label = '1h' option_choice.market_trend_reset = 3_600 when '45m' option_choice.market_trend_reset_label = '45m' option_choice.market_trend_reset = 2_700 when '30m' option_choice.market_trend_reset_label = '30m' option_choice.market_trend_reset = 1_800 when '15m' option_choice.market_trend_reset_label = '15m' option_choice.market_trend_reset = 900 when '5m' option_choice.market_trend_reset_label = '5m' option_choice.market_trend_reset = 300 when '3m' option_choice.market_trend_reset_label = '3m' option_choice.market_trend_reset = 180 when '1m' option_choice.market_trend_reset_label = '1m' option_choice.market_trend_reset = 60 else usage = true reason = :market_trend_reset end if usage case reason when :symbol puts "ERROR: --symbol Flag is Required.\n\n" when :session_root puts "ERROR: #{option_choice.session_root} does not exist.\n\n" when :market_trend_reset puts "ERROR: #{option_choice.market_trend_reset} - Possible values are: 1W, 1D, 4h, 3h, 2h, 1h, 45m, 30m, 15m, 5m, 3m, 1m\n\n" end puts `#{option_choice.driver_name} --help` exit 1 end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self) end # Display Usage for this Module public_class_method def self.help puts "USAGE: #{self}.check(option_choice: option_choice) " end end end end