class ParseGalenicForm
Public Class Methods
from_string(string)
click to toggle source
# File lib/oddb2xml/parslet_compositions.rb, line 482 def self.from_string(string) return nil if string.nil? stripped = string.gsub(/^"|["\n]+$/, "") return nil unless stripped puts "ParseGalenicForm.from_string #{string}" if VERBOSE_MESSAGES # /ng-tr/.match(Socket.gethostbyname(Socket.gethostname).first) parser = GalenicFormParser.new transf = GalenicFormTransformer.new begin if defined?(RSpec) ast = transf.apply(parser.parse_with_debug(string)) puts "#{File.basename(__FILE__)}:#{__LINE__}: ==> " if VERBOSE_MESSAGES pp ast if VERBOSE_MESSAGES else ast = transf.apply(parser.parse(string)) end rescue Parslet::ParseFailed => error @@error_handler.nrParsingErrors ||= 0 @@error_handler.nrParsingErrors += 1 puts "#{File.basename(__FILE__)}:#{__LINE__}: failed parsing ==> #{string} #{error}" return nil end return [] unless ast form = ast[:galenic_form] ? ast[:galenic_form].to_s.sub(/^\/\s+/, "") : nil name = ast[:prepation_name] ? ast[:prepation_name].to_s.strip : nil [name, form] end