Class: Parselly::ParseResult

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast = nil, errors = nil, **keywords) ⇒ ParseResult

Returns a new instance of ParseResult.



10
11
12
13
# File 'lib/parselly.rb', line 10

def initialize(ast = nil, errors = nil, **keywords)
  @ast = keywords.fetch(:ast, ast)
  @errors = keywords.fetch(:errors, errors || [])
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



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

def ast
  @ast
end

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

Instance Method Details

#deconstructObject



35
36
37
# File 'lib/parselly.rb', line 35

def deconstruct
  to_a
end

#deconstruct_keys(keys) ⇒ Object



39
40
41
42
43
44
# File 'lib/parselly.rb', line 39

def deconstruct_keys(keys)
  hash = { ast: ast, errors: errors }
  return hash if keys.nil?

  keys.each_with_object({}) { |key, result| result[key] = hash[key] if hash.key?(key) }
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  ast.nil?
end

#failure?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/parselly.rb', line 19

def failure?
  !success?
end

#first_errorObject



27
28
29
# File 'lib/parselly.rb', line 27

def first_error
  errors.first
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/parselly.rb', line 15

def success?
  errors.empty? && !ast.nil?
end

#to_aObject



31
32
33
# File 'lib/parselly.rb', line 31

def to_a
  [ast, errors]
end