Class: Pubid::Iec::Components::ConsolidatedAmendment
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Iec::Components::ConsolidatedAmendment
- Defined in:
- lib/pubid/iec/components/consolidated_amendment.rb
Overview
Consolidated Amendment component for chained amendments Single Responsibility: Represents multiple amendments combined with + notation Example: AMD1:2020AMD2:2022
Class Method Summary collapse
-
.parse(string) ⇒ Object
Parse consolidated amendment string like “+AMD1:2020+AMD2:2022” Each amendment has number and optional year.
Instance Method Summary collapse
-
#count ⇒ Object
Count of amendments in the chain.
-
#empty? ⇒ Boolean
Check if this consolidated amendment is empty.
- #to_s ⇒ Object
Class Method Details
.parse(string) ⇒ Object
Parse consolidated amendment string like “+AMD1:2020+AMD2:2022” Each amendment has number and optional year
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pubid/iec/components/consolidated_amendment.rb', line 32 def self.parse(string) amendment_parts = string.split("+").reject(&:empty?) amendments = amendment_parts.filter_map do |part| # Parse "AMD1:2020" format if part =~ /AMD(\d+):(\d{4})/ Amendment.new(number: $1, year: $2) elsif part =~ /AMD(\d+)/ Amendment.new(number: $1) end end new(amendments: amendments) end |
Instance Method Details
#count ⇒ Object
Count of amendments in the chain
53 54 55 |
# File 'lib/pubid/iec/components/consolidated_amendment.rb', line 53 def count amendments&.size || 0 end |
#empty? ⇒ Boolean
Check if this consolidated amendment is empty
48 49 50 |
# File 'lib/pubid/iec/components/consolidated_amendment.rb', line 48 def empty? amendments.nil? || amendments.empty? end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/pubid/iec/components/consolidated_amendment.rb', line 26 def to_s amendments.map { |amd| "+#{amd}" }.join end |