Class: Defmastership::Definition
- Inherits:
-
Object
- Object
- Defmastership::Definition
- Extended by:
- Forwardable
- Defined in:
- lib/defmastership/definition.rb
Overview
Defmastership definition: contains all data of a definition
Instance Method Summary collapse
-
#<<(new_line) ⇒ Definition
Add a line to the definition’s value.
-
#add_eref(ref, extrefs) ⇒ Object
Set an external ref list for a given reference type.
-
#add_iref(ref) ⇒ Object
Set an internal ref.
-
#initialize(match) ⇒ Definition
constructor
A new instance of Definition.
-
#set_attribute(key, value) ⇒ Object
Set an attribute for a given key.
-
#sha256_short ⇒ String
Short representation (8 last characters) of the sha256 of the definition’s value.
-
#value ⇒ String
Add a line to the definition’s value.
-
#wrong_explicit_checksum ⇒ String
The explicit checsum if wrong or nil.
Constructor Details
#initialize(match) ⇒ Definition
Returns a new instance of Definition.
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
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
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
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
113 114 115 |
# File 'lib/defmastership/definition.rb', line 113 def set_attribute(key, value) attributes[key] = value end |
#sha256_short ⇒ String
Returns 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 |
#value ⇒ String
Add a line to the definition’s value
78 79 80 |
# File 'lib/defmastership/definition.rb', line 78 def value lines.join("\n") end |
#wrong_explicit_checksum ⇒ String
Returns 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 |