Class: Metanorma::Release::DocumentId

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/release/document_id.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ DocumentId

Returns a new instance of DocumentId.



19
20
21
22
# File 'lib/metanorma/release/document_id.rb', line 19

def initialize(value)
  @value = value
  freeze
end

Class Method Details

.from_normalized(value) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
# File 'lib/metanorma/release/document_id.rb', line 13

def self.from_normalized(value)
  raise ArgumentError, 'Document ID cannot be empty' if value.nil? || value.strip.empty?

  new(value.to_s.strip)
end

.from_raw(raw_identifier) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/metanorma/release/document_id.rb', line 6

def self.from_raw(raw_identifier)
  normalized = raw_identifier.to_s.downcase.gsub(/[^a-z0-9]+/, '-').gsub(/^-|-$/, '')
  raise ArgumentError, 'Document ID cannot be empty' if normalized.empty?

  new(normalized)
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/metanorma/release/document_id.rb', line 36

def eql?(other)
  other.is_a?(self.class) && @value == other.to_s
end

#file_nameObject



32
33
34
# File 'lib/metanorma/release/document_id.rb', line 32

def file_name
  @value
end

#hashObject



40
41
42
# File 'lib/metanorma/release/document_id.rb', line 40

def hash
  @value.hash
end

#tag_prefixObject



28
29
30
# File 'lib/metanorma/release/document_id.rb', line 28

def tag_prefix
  @value
end

#to_sObject



24
25
26
# File 'lib/metanorma/release/document_id.rb', line 24

def to_s
  @value
end