Class: Transducer::Parser
- Inherits:
-
Object
- Object
- Transducer::Parser
- Defined in:
- lib/transducer/parser.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(file_path) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 14 |
# File 'lib/transducer/parser.rb', line 10 def initialize(file_path) @file_path = file_path @data = nil @errors = [] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/transducer/parser.rb', line 8 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/transducer/parser.rb', line 8 def errors @errors end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/transducer/parser.rb', line 8 def file_path @file_path end |
Instance Method Details
#parse ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/transducer/parser.rb', line 16 def parse raise FileError, "File not found: #{file_path}" unless File.exist?(file_path) begin @data = Psych.safe_load_file(file_path, permitted_classes: [Symbol, Date, Time]) rescue Psych::SyntaxError => e raise ParseError, "YAML syntax error at line #{e.line}: #{e.}" end validate_openapi_spec @data end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/transducer/parser.rb', line 29 def valid? @errors.empty? end |