Class: TechnicalAnalysis::Validation
- Inherits:
-
Object
- Object
- TechnicalAnalysis::Validation
- Defined in:
- lib/technical_analysis/helpers/validation.rb
Defined Under Namespace
Classes: ValidationError
Class Method Summary collapse
- .validate_date_time_key(data, date_time_key = :date_time) ⇒ Object
- .validate_length(data, size) ⇒ Object
- .validate_numeric_data(data, *keys) ⇒ Object
- .validate_options(options, valid_options) ⇒ Object
Class Method Details
.validate_date_time_key(data, date_time_key = :date_time) ⇒ Object
24 25 26 27 28 |
# File 'lib/technical_analysis/helpers/validation.rb', line 24 def self.validate_date_time_key(data, date_time_key=:date_time) unless data.all? { |row| row.keys.include? date_time_key } raise ValidationError.new "Dataset must include '#{date_time_key}' field with timestamps" end end |
.validate_length(data, size) ⇒ Object
12 13 14 |
# File 'lib/technical_analysis/helpers/validation.rb', line 12 def self.validate_length(data, size) raise ValidationError.new "Not enough data for that period" if data.size < size end |
.validate_numeric_data(data, *keys) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/technical_analysis/helpers/validation.rb', line 4 def self.validate_numeric_data(data, *keys) keys.each do |key| unless data.all? { |v| v[key].is_a? Numeric } raise ValidationError.new "Invalid Data. '#{key}' is not valid price data." end end end |
.validate_options(options, valid_options) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/technical_analysis/helpers/validation.rb', line 16 def self.(, ) raise ValidationError.new "Options must be a hash." unless .respond_to? :keys raise ValidationError.new "No valid options provided." unless return true if (.keys - ).empty? raise ValidationError.new "Invalid options provided. Valid options are #{.join(", ")}" end |