Class: Defmastership::Definition

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/defmastership/definition.rb

Overview

Defmastership definition: contains all data of a definition

Instance Method Summary collapse

Constructor Details

#initialize(match) ⇒ Definition

Returns a new instance of Definition.

Parameters:

  • match (MatchData)

    the definition data from regepx match



59
60
61
62
63
64
# File 'lib/defmastership/definition.rb', line 59

def initialize(match)
  @data = DefinitionData.new(
    *BUILD_FROM_MATCH.transform_values { |lamb| lamb.call(match) }
       .fetch_values(*DefinitionData.members)
  )
end

Instance Method Details

#<<(new_line) ⇒ Definition

Add a line to the definition’s value

Parameters:

  • new_line (String)

    the new line

Returns:



70
71
72
73
# File 'lib/defmastership/definition.rb', line 70

def <<(new_line)
  lines << new_line
  self
end

#add_eref(ref, extrefs) ⇒ Object

Set an external ref list for a given reference type

Parameters:

  • ref (String)

    the type of cross reference

  • extrefs (String)

    the comma separated external references



98
99
100
# File 'lib/defmastership/definition.rb', line 98

def add_eref(ref, extrefs)
  eref[ref] = extrefs.strip.split(/\s*,\s*/)
end

#add_iref(ref) ⇒ Object

Set an internal ref

Parameters:

  • ref (String)

    the internal reference



105
106
107
# File 'lib/defmastership/definition.rb', line 105

def add_iref(ref)
  iref << ref
end

#set_attribute(key, value) ⇒ Object

Set an attribute for a given key

Parameters:

  • key (String)

    the attribute’s key

  • value (String)

    the attribute’s value



113
114
115
# File 'lib/defmastership/definition.rb', line 113

def set_attribute(key, value)
  attributes[key] = value
end

#sha256_shortString

Returns short representation (8 last characters) of the sha256 of the definition’s value.

Returns:

  • (String)

    short representation (8 last characters) of the sha256 of the definition’s value



83
84
85
86
87
# File 'lib/defmastership/definition.rb', line 83

def sha256_short
  return "~#{Digest::SHA2.hexdigest(value).chars.last(8).join}" unless summary

  "~#{Digest::SHA2.hexdigest("#{summary}\n#{value}").chars.last(8).join}"
end

#valueString

Add a line to the definition’s value

Returns:

  • (String)

    the complete value of the definition



78
79
80
# File 'lib/defmastership/definition.rb', line 78

def value
  lines.join("\n")
end

#wrong_explicit_checksumString

Returns the explicit checsum if wrong or nil.

Returns:

  • (String)

    the explicit checsum if wrong or nil



90
91
92
# File 'lib/defmastership/definition.rb', line 90

def wrong_explicit_checksum
  explicit_checksum unless explicit_checksum.eql?(sha256_short)
end