Class: Openphar::Parsers::JpHtmlParserBase
- Inherits:
-
Object
- Object
- Openphar::Parsers::JpHtmlParserBase
- Defined in:
- lib/openphar/parsers/jp_html_parser_base.rb
Overview
Base class for JP HTML parsers
Provides common functionality for parsing Japan Pharmacopoeia HTML files. Subclasses should implement:
- #parse method
- Section pattern constants
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Class Method Summary collapse
-
.parse_file(file_path) ⇒ Array<Hash>
Parse monographs from a file.
-
.parse_files(file_paths) ⇒ Array<Hash>
Parse monographs from multiple files.
Instance Method Summary collapse
-
#initialize(html_content) ⇒ JpHtmlParserBase
constructor
Initialize parser with HTML content.
-
#parse ⇒ Array<Hash>
Parse monographs from the document Subclasses should override this method.
Constructor Details
#initialize(html_content) ⇒ JpHtmlParserBase
Initialize parser with HTML content
19 20 21 |
# File 'lib/openphar/parsers/jp_html_parser_base.rb', line 19 def initialize(html_content) @document = Nokogiri::HTML(html_content, nil, "UTF-8") end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
14 15 16 |
# File 'lib/openphar/parsers/jp_html_parser_base.rb', line 14 def document @document end |
Class Method Details
.parse_file(file_path) ⇒ Array<Hash>
Parse monographs from a file
35 36 37 38 |
# File 'lib/openphar/parsers/jp_html_parser_base.rb', line 35 def self.parse_file(file_path) html_content = File.read(file_path, encoding: "UTF-8") new(html_content).parse end |
.parse_files(file_paths) ⇒ Array<Hash>
Parse monographs from multiple files
44 45 46 |
# File 'lib/openphar/parsers/jp_html_parser_base.rb', line 44 def self.parse_files(file_paths) file_paths.flat_map { |path| parse_file(path) } end |
Instance Method Details
#parse ⇒ Array<Hash>
Parse monographs from the document Subclasses should override this method
27 28 29 |
# File 'lib/openphar/parsers/jp_html_parser_base.rb', line 27 def parse raise NotImplementedError, "Subclasses must implement #parse" end |