Class: DefMastership::Definition
- Inherits:
-
Object
- Object
- DefMastership::Definition
- Defined in:
- lib/defmastership/definition.rb
Overview
DefMastership definition: contains all data of a definition
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#eref ⇒ Object
readonly
Returns the value of attribute eref.
-
#explicit_version ⇒ Object
readonly
Returns the value of attribute explicit_version.
-
#iref ⇒ Object
readonly
Returns the value of attribute iref.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<<(new_line) ⇒ Object
- #add_eref(refname, extrefs) ⇒ Object
- #add_iref(ref) ⇒ Object
-
#initialize(match) ⇒ Definition
constructor
A new instance of Definition.
- #set_attribute(key, value) ⇒ Object
- #sha256 ⇒ Object
- #value ⇒ Object
- #wrong_explicit_checksum ⇒ Object
Constructor Details
#initialize(match) ⇒ Definition
Returns a new instance of Definition.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/defmastership/definition.rb', line 11 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 |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def attributes @attributes end |
#eref ⇒ Object (readonly)
Returns the value of attribute eref.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def eref @eref end |
#explicit_version ⇒ Object (readonly)
Returns the value of attribute explicit_version.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def explicit_version @explicit_version end |
#iref ⇒ Object (readonly)
Returns the value of attribute iref.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def iref @iref end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def labels @labels end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def lines @lines end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def reference @reference end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/defmastership/definition.rb', line 9 def type @type end |
Instance Method Details
#<<(new_line) ⇒ Object
24 25 26 27 |
# File 'lib/defmastership/definition.rb', line 24 def <<(new_line) @lines << new_line self end |
#add_eref(refname, extrefs) ⇒ Object
41 42 43 |
# File 'lib/defmastership/definition.rb', line 41 def add_eref(refname, extrefs) @eref[refname] = extrefs.strip.split(/\s*,\s*/) end |
#add_iref(ref) ⇒ Object
45 46 47 |
# File 'lib/defmastership/definition.rb', line 45 def add_iref(ref) @iref << ref end |
#set_attribute(key, value) ⇒ Object
49 50 51 |
# File 'lib/defmastership/definition.rb', line 49 def set_attribute(key, value) @attributes[key] = value end |
#sha256 ⇒ Object
33 34 35 |
# File 'lib/defmastership/definition.rb', line 33 def sha256 "~#{Digest::SHA2.new(256).hexdigest(value).split(//).last(8).join}" end |
#value ⇒ Object
29 30 31 |
# File 'lib/defmastership/definition.rb', line 29 def value @lines.join("\n") end |
#wrong_explicit_checksum ⇒ Object
37 38 39 |
# File 'lib/defmastership/definition.rb', line 37 def wrong_explicit_checksum @explicit_checksum if @explicit_checksum != sha256 end |