Class: Transducer::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/transducer/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/transducer/parser.rb', line 8

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/transducer/parser.rb', line 8

def errors
  @errors
end

#file_pathObject (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

#parseObject

Raises:



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.message}"
  end

  validate_openapi_spec
  @data
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/transducer/parser.rb', line 29

def valid?
  @errors.empty?
end