Class: DefMastership::Definition

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

Overview

DefMastership definition: contains all data of a definition

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/defmastership/definition.rb', line 9

def attributes
  @attributes
end

#erefObject (readonly)

Returns the value of attribute eref.



9
10
11
# File 'lib/defmastership/definition.rb', line 9

def eref
  @eref
end

#explicit_versionObject (readonly)

Returns the value of attribute explicit_version.



9
10
11
# File 'lib/defmastership/definition.rb', line 9

def explicit_version
  @explicit_version
end

#irefObject (readonly)

Returns the value of attribute iref.



9
10
11
# File 'lib/defmastership/definition.rb', line 9

def iref
  @iref
end

#labelsObject (readonly)

Returns the value of attribute labels.



9
10
11
# File 'lib/defmastership/definition.rb', line 9

def labels
  @labels
end

#linesObject (readonly)

Returns the value of attribute lines.



9
10
11
# File 'lib/defmastership/definition.rb', line 9

def lines
  @lines
end

#referenceObject (readonly)

Returns the value of attribute reference.



9
10
11
# File 'lib/defmastership/definition.rb', line 9

def reference
  @reference
end

#typeObject (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

#sha256Object



33
34
35
# File 'lib/defmastership/definition.rb', line 33

def sha256
  "~#{Digest::SHA2.new(256).hexdigest(value).split(//).last(8).join}"
end

#valueObject



29
30
31
# File 'lib/defmastership/definition.rb', line 29

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

#wrong_explicit_checksumObject



37
38
39
# File 'lib/defmastership/definition.rb', line 37

def wrong_explicit_checksum
  @explicit_checksum if @explicit_checksum != sha256
end