class J2119::Validator
Attributes
parsed[R]
Public Class Methods
new(assertions_source)
click to toggle source
# File lib/j2119.rb, line 35 def initialize assertions_source assertions = File.open(assertions_source, "r") @parser = Parser.new assertions end
Public Instance Methods
root()
click to toggle source
# File lib/j2119.rb, line 40 def root @parser.root end
to_s()
click to toggle source
# File lib/j2119.rb, line 72 def to_s "J2119 validator for instances of \"#{@parser.root}\"" end
validate(json_source)
click to toggle source
# File lib/j2119.rb, line 44 def validate json_source # already parsed? if json_source.is_a?(Hash) @parsed = json_source else if json_source.respond_to?(:read) text = json_source.read elsif File.readable? json_source text = File.read json_source else text = json_source end begin @parsed = JSON.parse text rescue Exception => e return [ "Problem reading/parsing JSON: #{e.to_s}" ] end end problems = [] validator = NodeValidator.new(@parser) validator.validate_node(@parsed, @parser.root, [ @parser.root ], problems) problems end