Class: Glossarist::ConceptEnricher
- Inherits:
-
Object
- Object
- Glossarist::ConceptEnricher
- Defined in:
- lib/glossarist/concept_enricher.rb
Instance Method Summary collapse
- #apply_uri_template(concepts, template) ⇒ Object
-
#inject_references(concepts) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity.
Instance Method Details
#apply_uri_template(concepts, template) ⇒ Object
28 29 30 31 32 |
# File 'lib/glossarist/concept_enricher.rb', line 28 def apply_uri_template(concepts, template) concepts.each do |mc| mc.data.uri = template.sub("{id}", mc.data.id.to_s) end end |
#inject_references(concepts) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/glossarist/concept_enricher.rb', line 5 def inject_references(concepts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity extractor = ReferenceExtractor.new concepts.each do |mc| mc.localizations.each do |l10n| refs = extractor.extract_from_localized_concept(l10n) next if refs.empty? existing = l10n.data.references || [] seen_keys = existing.to_set { |r| [r.source, r.concept_id] } refs.each do |ref| key = [ref.source, ref.concept_id] next if seen_keys.include?(key) seen_keys.add(key) existing << ref end l10n.data.references = existing end end end |