Class: PuppetStrings::Yard::Parsers::JSON::Parser
- Inherits:
-
YARD::Parser::Base
- Object
- YARD::Parser::Base
- PuppetStrings::Yard::Parsers::JSON::Parser
- Defined in:
- lib/puppet-strings/yard/parsers/json/parser.rb
Overview
Implementas a JSON parser.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #enumerator ⇒ Object
-
#initialize(source, filename) ⇒ void
constructor
Initializes the parser.
-
#parse ⇒ void
Parses the source.
Constructor Details
#initialize(source, filename) ⇒ void
Initializes the parser.
13 14 15 16 17 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 13 def initialize(source, filename) # rubocop:disable Lint/MissingSuper @file = filename @source = source @statements = [] end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 7 def file @file end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 7 def source @source end |
Instance Method Details
#enumerator ⇒ Object
19 20 21 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 19 def enumerator @statements end |
#parse ⇒ void
This method returns an undefined value.
Parses the source
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppet-strings/yard/parsers/json/parser.rb', line 25 def parse begin json = JSON.parse(source) # TODO: this should compare json to a Task metadata json-schema or perform some other hueristics # to determine what type of statement it represents @statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty? rescue StandardError log.error "Failed to parse #{@file}: " @statements = [] end @statements.freeze self end |