Class: Openphar::Parsers::BaseMonographParser
- Inherits:
-
Object
- Object
- Openphar::Parsers::BaseMonographParser
- Defined in:
- lib/openphar/parsers/base_monograph_parser.rb
Overview
Abstract base class for all monograph parsers.
Defines the contract that all parsers must follow:
- Return Lutaml::Model instances (not Hashes)
- Track parsing statistics
- Handle errors consistently
Instance Attribute Summary collapse
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
-
#initialize ⇒ BaseMonographParser
constructor
A new instance of BaseMonographParser.
-
#parse(source) ⇒ Lutaml::Model::Serializable?
Parse a single source (string, file content, etc.) Subclasses MUST implement this method.
-
#parse_directory(directory) ⇒ Array<Lutaml::Model::Serializable>
Parse all files in a directory.
-
#parse_file(file_path) ⇒ Lutaml::Model::Serializable?
Parse a single file.
-
#reset_stats ⇒ Object
Reset parsing statistics.
Constructor Details
#initialize ⇒ BaseMonographParser
Returns a new instance of BaseMonographParser.
22 23 24 25 26 27 28 29 |
# File 'lib/openphar/parsers/base_monograph_parser.rb', line 22 def initialize @stats = { total: 0, parsed: 0, failed: 0, errors: [] } end |
Instance Attribute Details
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
20 21 22 |
# File 'lib/openphar/parsers/base_monograph_parser.rb', line 20 def stats @stats end |
Instance Method Details
#parse(source) ⇒ Lutaml::Model::Serializable?
Parse a single source (string, file content, etc.) Subclasses MUST implement this method.
37 38 39 |
# File 'lib/openphar/parsers/base_monograph_parser.rb', line 37 def parse(source) raise NotImplementedError, 'Subclasses must implement #parse' end |
#parse_directory(directory) ⇒ Array<Lutaml::Model::Serializable>
Parse all files in a directory. Subclasses MUST implement this method.
57 58 59 |
# File 'lib/openphar/parsers/base_monograph_parser.rb', line 57 def parse_directory(directory) raise NotImplementedError, 'Subclasses must implement #parse_directory' end |
#parse_file(file_path) ⇒ Lutaml::Model::Serializable?
Parse a single file. Subclasses MUST implement this method.
47 48 49 |
# File 'lib/openphar/parsers/base_monograph_parser.rb', line 47 def parse_file(file_path) raise NotImplementedError, 'Subclasses must implement #parse_file' end |
#reset_stats ⇒ Object
Reset parsing statistics
62 63 64 65 66 67 68 69 |
# File 'lib/openphar/parsers/base_monograph_parser.rb', line 62 def reset_stats @stats = { total: 0, parsed: 0, failed: 0, errors: [] } end |