Sha256: 62662eee0b6f6a3d3fbe2c4f4b36f6333d55a2f2b28853070e00067d7b0adf96

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require "sip_validator/version"
require 'sip_validator/loader'
require 'sip_validator/validator'

module SipValidator
  class Runner
    class << self  
      def run(file_names)
        num_valid = 0
        num_invalid = 0
        num_error = 0
        total = 0
        puts "\n"
        statuses = []
        types = []
        categories = []
        layers = []
        file_names.map do |file_name|
          # Disable file check
          # unless file_name.match(/.*sip-\d+.md$/)
          #   puts "Warning: #{file_name} does not match sip file format"
          #   next
          # end
          attributes = Loader.load(file_name)
          total+=1
          begin 
            v = Validator.new(attributes)
            if v.valid?
              num_valid+=1      
            else
              num_invalid+=1
              puts "#{file_name} is NOT valid:\t #{v.errors.messages}"
            end
            statuses.push v.status
          rescue => e
            puts "Warning: #{file_name} \t #{e}"
            num_error+=1
          end
        end
              
        puts "\n\ntotal:#{total}, valid:#{num_valid}, invalid:#{num_invalid}, errors:#{num_error}"
        puts "\tstatuses: #{aggregate(statuses)}"
        raise "#{num_invalid} invalid entities" unless num_invalid == 0
      end

      private

      def aggregate(array)
        array.group_by{|k,v| k}.map{|k,v| [k,v.length]}
      end  
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sip_validator-0.1.1 lib/sip_validator.rb
sip_validator-0.1.0 lib/sip_validator.rb