Class: Openphar::Parsers::JpHtmlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/openphar/parsers/jp_html_parser.rb

Overview

Parser for Japan Pharmacopoeia HTML monographs

Constant Summary collapse

SECTION_PATTERNS =

JP monograph section patterns

{
  definition: /(?:Definition|Origin and Definition)/i,
  identification: /Identification/i,
  purity: /Purity/i,
  assay: /Assay/i,
  storage: /Containers and Storage/i
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html_content) ⇒ JpHtmlParser

Returns a new instance of JpHtmlParser.



18
19
20
21
# File 'lib/openphar/parsers/jp_html_parser.rb', line 18

def initialize(html_content)
  @document = Nokogiri::HTML(html_content)
  @monographs = []
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



16
17
18
# File 'lib/openphar/parsers/jp_html_parser.rb', line 16

def document
  @document
end

#monographsObject (readonly)

Returns the value of attribute monographs.



16
17
18
# File 'lib/openphar/parsers/jp_html_parser.rb', line 16

def monographs
  @monographs
end

Instance Method Details

#parseObject

Parse all monographs from the document



24
25
26
27
28
29
30
31
32
33
# File 'lib/openphar/parsers/jp_html_parser.rb', line 24

def parse
  # JP HTML structure varies; this is a template
  monograph_nodes = document.css(".monograph, .crude-drug")

  monograph_nodes.each do |node|
    monographs << parse_monograph(node)
  end

  monographs
end