Sha256: f9ada7eafa3876b240524edec22c06f349a1d47aef148a9ecb49f2218ca70de9
Contents?: true
Size: 1.76 KB
Versions: 25
Compression:
Stored size: 1.76 KB
Contents
# frozen_string_literal: true # (c) Copyright 2021 Ribose Inc. # module Glossarist class Citation < Model # Unstructured (plain text) reference. # @return [String] attr_accessor :text # Source in structured reference. # @return [String] attr_accessor :source # Document ID in structured reference. # @return [String] attr_accessor :id # Document version in structured reference. # @return [String] attr_accessor :version # @return [String] # Referred clause of the document. attr_accessor :clause # Link to document. # @return [String] attr_accessor :link # Original ref text before parsing. # @return [String] # @note This attribute is likely to be removed or reworked in future. # It is arguably not relevant to Glossarist itself. attr_accessor :original # Whether it is a plain text ref. # @return [Boolean] def plain? (source && id && version).nil? end # Whether it is a structured ref. # @return [Boolean] def structured? !plain? end def to_h { "ref" => ref_to_h, "clause" => clause, "link" => link, "original" => original, }.compact end def self.from_h(hash) hash = hash.dup ref_val = hash.delete("ref") hash.merge!(Hash === ref_val ? ref_val : {"text" => ref_val}) hash.compact! super(hash) end def ref=(ref) if ref.is_a?(Hash) @source = ref["source"] @id = ref["id"] @version = ref["version"] else @text = ref end end private def ref_to_h if structured? { "source" => source, "id" => id, "version" => version }.compact else text end end end end
Version data entries
25 entries across 25 versions & 2 rubygems