Class: J2119::Validator
- Inherits:
-
Object
- Object
- J2119::Validator
- Defined in:
- lib/j2119.rb
Instance Attribute Summary collapse
-
#parsed ⇒ Object
readonly
Returns the value of attribute parsed.
Instance Method Summary collapse
-
#initialize(assertions_source) ⇒ Validator
constructor
A new instance of Validator.
- #root ⇒ Object
- #to_s ⇒ Object
- #validate(json_source) ⇒ Object
Constructor Details
Instance Attribute Details
#parsed ⇒ Object (readonly)
Returns the value of attribute parsed.
33 34 35 |
# File 'lib/j2119.rb', line 33 def parsed @parsed end |
Instance Method Details
#to_s ⇒ Object
72 73 74 |
# File 'lib/j2119.rb', line 72 def to_s "J2119 validator for instances of \"#{@parser.root}\"" end |
#validate(json_source) ⇒ Object
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 70 |
# 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 |