class Spout::Models::CoverageResult

Contains the coverage of a specific variable.

Attributes

csv_values[RW]
domain_test[RW]
error[RW]
error_message[RW]
file_name_test[RW]
json[RW]
json_id_test[RW]
valid_values[RW]
values_test[RW]
variable_type_test[RW]

Public Class Methods

new(column, csv_values) click to toggle source
# File lib/spout/models/coverage_result.rb, line 13
def initialize(column, csv_values)
  load_json(column)
  load_valid_values

  @csv_values = csv_values
  @values_test = check_values
  @variable_type_test = check_variable_type
  @domain_test = check_domain_specified
end

Public Instance Methods

check_domain_specified() click to toggle source
# File lib/spout/models/coverage_result.rb, line 53
def check_domain_specified
  if @json["type"] != "choices" && domain_name == ""
    true
  else
    domain_file = Dir.glob("domains/**/#{@json['domain'].to_s.downcase}.json", File::FNM_CASEFOLD).first
    if domain_json = JSON.parse(File.read(domain_file, encoding: "utf-8")) rescue false
      return domain_json.is_a?(Array)
    end
    false
  end
end
check_values() click to toggle source
# File lib/spout/models/coverage_result.rb, line 45
def check_values
  @json["type"] != "choices" || (@valid_values | @csv_values.compact).size == @valid_values.size
end
check_variable_type() click to toggle source
# File lib/spout/models/coverage_result.rb, line 49
def check_variable_type
  Spout::Tests::VariableTypeValidation::VALID_VARIABLE_TYPES.include?(@json["type"])
end
domain_name() click to toggle source
# File lib/spout/models/coverage_result.rb, line 69
def domain_name
  @json["domain"].to_s.downcase.strip
end
errored?() click to toggle source
# File lib/spout/models/coverage_result.rb, line 65
def errored?
  error == true
end
load_json(column) click to toggle source
# File lib/spout/models/coverage_result.rb, line 23
def load_json(column)
  file = Dir.glob("variables/**/#{column.to_s.downcase}.json", File::FNM_CASEFOLD).first
  @file_name_test = !file.nil?
  @json = JSON.parse(File.read(file, encoding: "utf-8")) rescue @json = {}
  @json_id_test = (@json["id"].to_s.downcase == column)
end
load_valid_values() click to toggle source
# File lib/spout/models/coverage_result.rb, line 30
def load_valid_values
  valid_values = []
  if @json["type"] == "choices" || domain_name != ""
    file = Dir.glob("domains/**/#{@json['domain'].to_s.downcase}.json", File::FNM_CASEFOLD).first
    if json = JSON.parse(File.read(file, encoding: "utf-8")) rescue false
      valid_values = json.collect { |hash| hash["value"] }
    end
  end
  @valid_values = valid_values
end
number_of_errors() click to toggle source
# File lib/spout/models/coverage_result.rb, line 41
def number_of_errors
  @file_name_test && @json_id_test && @values_test && @variable_type_test && @domain_test ? 0 : 1
end