Class: Framecurve::Validator
- Inherits:
-
Object
- Object
- Framecurve::Validator
- Defined in:
- lib/framecurve/validator.rb
Overview
Validates a Curve object for well-formedness and completeness.
v = Validator.new
v.parse(io_handle)
v.errors => []
v.warnings => ["Do not put cusswords in your framecurves"]
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#any_errors? ⇒ Boolean
Tells whether this validator instance has any errors.
-
#any_warnings? ⇒ Boolean
Tells whether this validator instance has any warnings.
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
-
#ok? ⇒ Boolean
Returns true if validation has been performed and there are no warnings and no errors.
-
#parse_and_validate(path_or_io) ⇒ Object
Parse and validate a file (API similar to Parser#parse).
-
#validate(curve) ⇒ Object
Validate a passed Curve object.
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
9 10 11 |
# File 'lib/framecurve/validator.rb', line 9 def initialize @warnings, @errors, @performed = [], [], false end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/framecurve/validator.rb', line 7 def errors @errors end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
7 8 9 |
# File 'lib/framecurve/validator.rb', line 7 def warnings @warnings end |
Instance Method Details
#any_errors? ⇒ Boolean
Tells whether this validator instance has any errors
14 15 16 |
# File 'lib/framecurve/validator.rb', line 14 def any_errors? @errors.any? end |
#any_warnings? ⇒ Boolean
Tells whether this validator instance has any warnings
19 20 21 |
# File 'lib/framecurve/validator.rb', line 19 def any_warnings? @warnings.any? end |
#ok? ⇒ Boolean
Returns true if validation has been performed and there are no warnings and no errors
42 43 44 |
# File 'lib/framecurve/validator.rb', line 42 def ok? @performed && !any_errors? && !any_warnings? end |
#parse_and_validate(path_or_io) ⇒ Object
Parse and validate a file (API similar to Parser#parse)
24 25 26 27 28 29 30 |
# File 'lib/framecurve/validator.rb', line 24 def parse_and_validate(path_or_io) begin validate(Framecurve::Parser.new.parse(path_or_io)) rescue Framecurve::Malformed => e @errors.push(e.) end end |
#validate(curve) ⇒ Object
Validate a passed Curve object
33 34 35 36 37 38 39 |
# File 'lib/framecurve/validator.rb', line 33 def validate(curve) initialize # reset methods_matching(/^(verify|recommend)/).each do | method_name | method(method_name).call(curve) end @performed = true end |