lib/MESH/heading.rb in mesh-medical-subject-headings-2.0.3 vs lib/MESH/heading.rb in mesh-medical-subject-headings-2.0.4

- old
+ new

@@ -1,10 +1,11 @@ module MESH class Heading include Comparable attr_accessor :unique_id, :tree_numbers, :roots, :parents, :children, :useful, :descriptor_class, :default_locale + attr_reader :linkified_summary def <=> other self.unique_id <=> other.unique_id end @@ -19,16 +20,19 @@ def summary(locale = default_locale) return @summary[locale] end def linkify_summary - linkified_summary = summary.dup - linkified_summary.scan(/[A-Z]+[A-Z,\s]+[A-Z]+/).each do |text| - heading = @tree.where(entries: /^#{text.strip}$/i).first - replacement_text = yield text, heading - linkified_summary.sub!(text, replacement_text) + return if summary.nil? + @linkified_summary = summary.dup + @linkified_summary.scan(/[A-Z]+[A-Z,\s]+[A-Z]+/).each do |text| + heading = @tree.find_by_entry(text) + if heading + replacement_text = yield text, heading + @linkified_summary.sub!(text, replacement_text) + end end - linkified_summary + @linkified_summary end def entries(locale = default_locale) @entries[locale] ||= [] return @entries[locale]