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.
61 62 63 64 65 66 |
# File 'lib/defmastership/definition.rb', line 61 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
72 73 74 75 |
# File 'lib/defmastership/definition.rb', line 72 def <<(new_line) lines << new_line self end |
#add_eref(ref, extrefs) ⇒ Object
Set an external ref list for a given reference type
100 101 102 |
# File 'lib/defmastership/definition.rb', line 100 def add_eref(ref, extrefs) eref[ref] = extrefs.strip.split(/\s*,\s*/) end |
#add_iref(ref) ⇒ Object
Set an internal ref
107 108 109 |
# File 'lib/defmastership/definition.rb', line 107 def add_iref(ref) iref << ref end |
#set_attribute(key, value) ⇒ Object
Set an attribute for a given key
115 116 117 |
# File 'lib/defmastership/definition.rb', line 115 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.
85 86 87 88 89 |
# File 'lib/defmastership/definition.rb', line 85 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
80 81 82 |
# File 'lib/defmastership/definition.rb', line 80 def value lines.join("\n") end |
#wrong_explicit_checksum ⇒ String
Returns the explicit checsum if wrong or nil.
92 93 94 |
# File 'lib/defmastership/definition.rb', line 92 def wrong_explicit_checksum explicit_checksum unless explicit_checksum.eql?(sha256_short) end |