Class: Metanorma::Release::DocumentId
- Inherits:
-
Object
- Object
- Metanorma::Release::DocumentId
- Defined in:
- lib/metanorma/release/document_id.rb
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #file_name ⇒ Object
- #hash ⇒ Object
-
#initialize(value) ⇒ DocumentId
constructor
A new instance of DocumentId.
- #tag_prefix ⇒ Object
- #to_s ⇒ Object
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
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
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
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_name ⇒ Object
32 33 34 |
# File 'lib/metanorma/release/document_id.rb', line 32 def file_name @value end |
#hash ⇒ Object
40 41 42 |
# File 'lib/metanorma/release/document_id.rb', line 40 def hash @value.hash end |
#tag_prefix ⇒ Object
28 29 30 |
# File 'lib/metanorma/release/document_id.rb', line 28 def tag_prefix @value end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/metanorma/release/document_id.rb', line 24 def to_s @value end |