# Copyright (c) 2020 Jerome Arbez-Gindre # frozen_string_literal: true require 'digest' module DefMastership # DefMastership definition: contains all data of a definition class Definition attr_reader :type, :reference, :lines, :labels, :eref, :iref, :attributes, :explicit_version def initialize(match) @type = match[:type] @reference = match[:reference] @lines = [] @labels = Set.new @labels.merge(match[:labels].split(/\s*,\s*/).to_set) if match[:labels] @eref = Hash.new([]) @iref = [] @attributes = {} @explicit_checksum = match[:explicit_checksum] @explicit_version = match[:explicit_version] end def <<(new_line) @lines << new_line self end def value @lines.join("\n") end def sha256 "~#{Digest::SHA2.new(256).hexdigest(value).chars.last(8).join}" end def wrong_explicit_checksum @explicit_checksum if @explicit_checksum != sha256 end def add_eref(refname, extrefs) @eref[refname] = extrefs.strip.split(/\s*,\s*/) end def add_iref(ref) @iref << ref end def set_attribute(key, value) @attributes[key] = value end end end