Class: Parselly::ParseResult
- Inherits:
-
Object
- Object
- Parselly::ParseResult
- Defined in:
- lib/parselly.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #deconstruct ⇒ Object
- #deconstruct_keys(keys) ⇒ Object
- #empty? ⇒ Boolean
- #failure? ⇒ Boolean
- #first_error ⇒ Object
-
#initialize(ast = nil, errors = nil, **keywords) ⇒ ParseResult
constructor
A new instance of ParseResult.
- #success? ⇒ Boolean
- #to_a ⇒ Object
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
#ast ⇒ Object
Returns the value of attribute ast.
8 9 10 |
# File 'lib/parselly.rb', line 8 def ast @ast end |
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/parselly.rb', line 8 def errors @errors end |
Instance Method Details
#deconstruct ⇒ Object
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
23 24 25 |
# File 'lib/parselly.rb', line 23 def empty? ast.nil? end |
#failure? ⇒ Boolean
19 20 21 |
# File 'lib/parselly.rb', line 19 def failure? !success? end |
#first_error ⇒ Object
27 28 29 |
# File 'lib/parselly.rb', line 27 def first_error errors.first end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/parselly.rb', line 15 def success? errors.empty? && !ast.nil? end |
#to_a ⇒ Object
31 32 33 |
# File 'lib/parselly.rb', line 31 def to_a [ast, errors] end |