Class: Spout::Commands::Coverage
- Inherits:
-
Object
- Object
- Spout::Commands::Coverage
- Includes:
- Helpers::NumberHelper
- Defined in:
- lib/spout/commands/coverage.rb
Overview
Generate a coverage report for the data dictionary.
Instance Method Summary collapse
-
#initialize(standard_version, argv) ⇒ Coverage
constructor
A new instance of Coverage.
- #run_coverage_report! ⇒ Object
Methods included from Helpers::NumberHelper
Constructor Details
#initialize(standard_version, argv) ⇒ Coverage
Returns a new instance of Coverage.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/spout/commands/coverage.rb', line 19 def initialize(standard_version, argv) @standard_version = standard_version @console = !argv.delete("--console").nil? @variable_files = Dir.glob("variables/**/*.json") @valid_ids = [] @number_of_rows = nil @config = Spout::Helpers::ConfigReader.new @subject_loader = Spout::Helpers::SubjectLoader.new( @variable_files, @valid_ids, @standard_version, @number_of_rows, @config.visit ) @subject_loader.load_subjects_from_csvs_part_one! # Not Part Two which is essentially cleaning the data @subjects = @subject_loader.subjects run_coverage_report! end |
Instance Method Details
#run_coverage_report! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/spout/commands/coverage.rb', line 34 def run_coverage_report! puts "Generating: index.html\n\n" @matching_results = [] @subject_loader.all_methods.each do |method, csv_files| scr = Spout::Models::CoverageResult.new(method, @subjects.collect(&method.to_sym).compact_empty.uniq) @matching_results << [csv_files, method, scr] end variable_ids = Dir.glob("variables/**/*.json").collect { |file| file.gsub(%r{^(.*)/|\.json$}, "").downcase } @extra_variable_ids = (variable_ids - @subject_loader.all_methods.keys).sort @subject_loader.load_variable_domains! domain_ids = Dir.glob("domains/**/*.json").collect { |file| file.gsub(%r{^(.*)/|\.json$}, "").downcase } @extra_domain_ids = (domain_ids - @subject_loader.all_domains).sort @matching_results.sort! do |a, b| [b[2].number_of_errors, a[0].to_s, a[1].to_s] <=> [a[2].number_of_errors, b[0].to_s, b[1].to_s] end @coverage_results = [] @subject_loader.csv_files.each do |csv_file| total_column_count = @matching_results.select { |mr| mr[0].include?(csv_file) }.count mapped_column_count = @matching_results .select { |mr| mr[0].include?(csv_file) && mr[2].number_of_errors.zero? }.count @coverage_results << [csv_file, total_column_count, mapped_column_count] end coverage_folder = File.join(Dir.pwd, "coverage") FileUtils.mkpath coverage_folder coverage_file = File.join(coverage_folder, "index.html") File.open(coverage_file, "w+") do |file| erb_location = File.join(File.dirname(__FILE__), "../views/index.html.erb") file.puts ERB.new(File.read(erb_location)).result(binding) end unless @console open_command = "open" unless RUBY_PLATFORM.match(/darwin/).nil? open_command = "start" unless RUBY_PLATFORM.match(/mingw/).nil? system "#{open_command} #{coverage_file}" if %w(start open).include?(open_command) end puts "#{coverage_file}\n\n" end |