Class: RubyJsonParser::Result

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_json_parser/result.rb

Overview

The result of parsing a JSON string/file. Combines an AST (Abstract Syntax Tree) and a list of errors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast, errors) ⇒ Result

Returns a new instance of Result.



17
18
19
20
# File 'lib/ruby_json_parser/result.rb', line 17

def initialize(ast, errors)
  @ast = ast
  @errors = errors
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



11
12
13
# File 'lib/ruby_json_parser/result.rb', line 11

def ast
  @ast
end

#errorsObject (readonly)

Returns the value of attribute errors.



14
15
16
# File 'lib/ruby_json_parser/result.rb', line 14

def errors
  @errors
end

Instance Method Details

#err?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby_json_parser/result.rb', line 23

def err?
  @errors.any?
end

#inspectObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_json_parser/result.rb', line 28

def inspect
  buff = String.new
  buff << "<RubyJsonParser::Result>\n"
  if @errors.any?
    buff << "  !Errors!\n"
    @errors.each do |err|
      buff << "    - #{err}\n"
    end
    buff << "\n"
  end

  buff << "  AST:\n"
  buff << @ast.inspect(2)
end