Class: Spout::Models::CoverageResult
- Inherits:
-
Object
- Object
- Spout::Models::CoverageResult
- Defined in:
- lib/spout/models/coverage_result.rb
Overview
Contains the coverage of a specific variable.
Instance Attribute Summary collapse
-
#csv_values ⇒ Object
Returns the value of attribute csv_values.
-
#domain_test ⇒ Object
Returns the value of attribute domain_test.
-
#error ⇒ Object
Returns the value of attribute error.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#file_name_test ⇒ Object
Returns the value of attribute file_name_test.
-
#json ⇒ Object
Returns the value of attribute json.
-
#json_id_test ⇒ Object
Returns the value of attribute json_id_test.
-
#valid_values ⇒ Object
Returns the value of attribute valid_values.
-
#values_test ⇒ Object
Returns the value of attribute values_test.
-
#variable_type_test ⇒ Object
Returns the value of attribute variable_type_test.
Instance Method Summary collapse
- #check_domain_specified ⇒ Object
- #check_values ⇒ Object
- #check_variable_type ⇒ Object
- #domain_name ⇒ Object
- #errored? ⇒ Boolean
-
#initialize(column, csv_values) ⇒ CoverageResult
constructor
A new instance of CoverageResult.
- #load_json(column) ⇒ Object
- #load_valid_values ⇒ Object
- #number_of_errors ⇒ Object
Constructor Details
#initialize(column, csv_values) ⇒ CoverageResult
Returns a new instance of CoverageResult.
13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#csv_values ⇒ Object
Returns the value of attribute csv_values.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def csv_values @csv_values end |
#domain_test ⇒ Object
Returns the value of attribute domain_test.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def domain_test @domain_test end |
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def error @error end |
#error_message ⇒ Object
Returns the value of attribute error_message.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def @error_message end |
#file_name_test ⇒ Object
Returns the value of attribute file_name_test.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def file_name_test @file_name_test end |
#json ⇒ Object
Returns the value of attribute json.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def json @json end |
#json_id_test ⇒ Object
Returns the value of attribute json_id_test.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def json_id_test @json_id_test end |
#valid_values ⇒ Object
Returns the value of attribute valid_values.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def valid_values @valid_values end |
#values_test ⇒ Object
Returns the value of attribute values_test.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def values_test @values_test end |
#variable_type_test ⇒ Object
Returns the value of attribute variable_type_test.
9 10 11 |
# File 'lib/spout/models/coverage_result.rb', line 9 def variable_type_test @variable_type_test end |
Instance Method Details
#check_domain_specified ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
45 46 47 |
# 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 ⇒ Object
49 50 51 |
# 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 ⇒ Object
69 70 71 |
# File 'lib/spout/models/coverage_result.rb', line 69 def domain_name @json["domain"].to_s.downcase.strip end |
#errored? ⇒ Boolean
65 66 67 |
# File 'lib/spout/models/coverage_result.rb', line 65 def errored? error == true end |
#load_json(column) ⇒ Object
23 24 25 26 27 28 |
# 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 ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
41 42 43 |
# 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 |